From 7b7b12b59356eb95d0d736dd255e0f186cf7ca71 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 8 Sep 2017 11:20:55 -0300 Subject: [PATCH] Fix bug "Rewind on Stop" increments start frame randomly (fix #1569) --- src/app/ui/editor/play_state.cpp | 10 ++++++---- src/ui/timer.cpp | 12 +++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/app/ui/editor/play_state.cpp b/src/app/ui/editor/play_state.cpp index cc5da280b..7281a9cc6 100644 --- a/src/app/ui/editor/play_state.cpp +++ b/src/app/ui/editor/play_state.cpp @@ -92,13 +92,13 @@ void PlayState::onEnterState(Editor* editor) EditorState::LeaveAction PlayState::onLeaveState(Editor* editor, EditorState* newState) { + // We don't stop the timer if we are going to the ScrollingState + // (we keep playing the animation). if (!m_toScroll) { + m_playTimer.stop(); + if (m_playOnce || Preferences::instance().general.rewindOnStop()) m_editor->setFrame(m_refFrame); - - // We don't stop the timer if we are going to the ScrollingState - // (we keep playing the animation). - m_playTimer.stop(); } return KeepState; } @@ -169,6 +169,8 @@ bool PlayState::onSetCursor(Editor* editor, const gfx::Point& mouseScreenPos) void PlayState::onPlaybackTick() { + ASSERT(m_playTimer.isRunning()); + if (m_nextFrameTime < 0) return; diff --git a/src/ui/timer.cpp b/src/ui/timer.cpp index 5838e86c3..1a95ac776 100644 --- a/src/ui/timer.cpp +++ b/src/ui/timer.cpp @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2001-2016 David Capello +// Copyright (C) 2001-2017 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -41,8 +41,8 @@ Timer::~Timer() ASSERT(it != timers.end()); timers.erase(it); - // Remove messages of this timer in the queue - Manager::getDefault()->removeMessagesForTimer(this); + // Stop the timer and remove it from the message queue. + stop(); } void Timer::start() @@ -54,6 +54,12 @@ void Timer::start() void Timer::stop() { m_running = false; + + // Remove messages of this timer in the queue. The expected behavior + // is that when we stop a timer, we'll not receive more messages + // about it (even if there are enqueued messages waiting in the + // message queue). + Manager::getDefault()->removeMessagesForTimer(this); } void Timer::tick()