Skip to content

Commit

Permalink
Fix crash using "play once" (fix #1337)
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Nov 30, 2016
1 parent e0a017a commit aa8cf94
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/app/ui/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,17 @@ void Editor::setStateInternal(const EditorStatePtr& newState)
else {
m_state->onBeforePopState(this);

// Save the current state into "m_deletedStates" just to keep a
// reference to it to avoid delete it right now. We'll delete it
// in the next Editor::onProcessMessage().
//
// This is necessary for PlayState because it removes itself
// calling Editor::stop() from PlayState::onPlaybackTick(). If we
// delete the PlayState inside the "Tick" timer signal, the
// program will crash (because we're iterating the
// PlayState::m_playTimer slots).
m_deletedStates.push(m_state);

m_statesHistory.pop();
m_state = m_statesHistory.top();
}
Expand Down Expand Up @@ -1209,6 +1220,10 @@ app::Color Editor::getColorByPosition(const gfx::Point& mousePos)

bool Editor::onProcessMessage(Message* msg)
{
// Delete states
if (!m_deletedStates.empty())
m_deletedStates.clear();

switch (msg->type()) {

case kTimerMessage:
Expand Down Expand Up @@ -1717,6 +1732,7 @@ void Editor::showAnimationSpeedMultiplierPopup(Option<bool>& playOnce,
menu.showPopup(ui::get_mouse_position());

if (isPlaying()) {
// Re-play
stop();
play(playOnce(),
playAll());
Expand Down
1 change: 1 addition & 0 deletions src/app/ui/editor/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ namespace app {

// Stack of states. The top element in the stack is the current state (m_state).
EditorStatesHistory m_statesHistory;
EditorStatesHistory m_deletedStates;

// Current editor state (it can be shared between several editors to
// the same document). This member cannot be NULL.
Expand Down
4 changes: 3 additions & 1 deletion src/app/ui/editor/editor_states_history.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
Expand All @@ -21,6 +21,8 @@ namespace app {
EditorStatesHistory();
~EditorStatesHistory();

bool empty() const { return m_states.empty(); }

// Gets the current state.
EditorStatePtr top();

Expand Down

0 comments on commit aa8cf94

Please sign in to comment.