Fix crash if we remove a tag when we're playing the animation

This commit is contained in:
David Capello 2022-10-20 14:51:42 -03:00
parent 9601c02812
commit 6c2d2f6f79
3 changed files with 21 additions and 0 deletions

View File

@ -192,6 +192,8 @@ void PlayState::onRemoveTag(Editor* editor, doc::Tag* tag)
{
if (m_tag == tag)
m_tag = nullptr;
m_playback.removeReferencesToTag(tag);
}
void PlayState::onPlaybackTick()

View File

@ -10,6 +10,7 @@
#include "doc/playback.h"
#include "base/remove_from_container.h"
#include "doc/frame.h"
#include "doc/sprite.h"
#include "doc/tag.h"
@ -144,6 +145,20 @@ Tag* Playback::tag() const
return (!m_playing.empty() ? const_cast<Tag*>(m_playing.back()->tag): nullptr);
}
void Playback::removeReferencesToTag(Tag* tag)
{
base::remove_from_container(m_tags, tag);
base::remove_from_container(m_played, tag);
for (auto it=m_playing.begin(); it!=m_playing.end(); ) {
std::unique_ptr<PlayTag>& playTag = *it;
if (playTag->tag == tag)
it = m_playing.erase(it);
else
++it;
}
}
void Playback::handleEnterFrame(const frame_t frameDelta, const bool firstTime)
{
PLAY_TRACE(" handleEnterFrame", m_frame, "+", frameDelta);

View File

@ -76,6 +76,10 @@ namespace doc {
// The tag that is being played right now (can be nullptr).
Tag* tag() const;
// Should be called when a specific tag is going to be deleted so
// we remove all references to this tag.
void removeReferencesToTag(Tag* tag);
private:
// Information about playing tags (and inner tags)
struct PlayTag {