From 768b69113a8eb6070870a088f3f7d309ebd75ee4 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 26 Mar 2021 11:40:10 -0300 Subject: [PATCH] Disconnect from BeforeCommandExecution signal onBeforePopState to avoid double backToPreviousState() calls In some special cases (several key press enqueued?) we can receive a BeforeCommandExecution signal when we are not part of the Editor state stack anymore. Related to 5ba8cecddebb789bf2266a1600ea4c7f56fc34b7 --- src/app/ui/editor/drawing_state.cpp | 8 +++++++- src/app/ui/editor/drawing_state.h | 3 ++- src/app/ui/editor/moving_cel_state.cpp | 16 ++++++---------- src/app/ui/editor/moving_cel_state.h | 3 +-- src/app/ui/editor/play_state.cpp | 8 +++++++- src/app/ui/editor/play_state.h | 3 ++- src/observable | 2 +- 7 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/app/ui/editor/drawing_state.cpp b/src/app/ui/editor/drawing_state.cpp index 64414cc49..7844a4510 100644 --- a/src/app/ui/editor/drawing_state.cpp +++ b/src/app/ui/editor/drawing_state.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2020 Igara Studio S.A. +// Copyright (C) 2018-2021 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -103,6 +103,12 @@ void DrawingState::notifyToolLoopModifiersChange(Editor* editor) m_toolLoopManager->notifyToolLoopModifiersChange(); } +void DrawingState::onBeforePopState(Editor* editor) +{ + m_beforeCmdConn.disconnect(); + StandbyState::onBeforePopState(editor); +} + bool DrawingState::onMouseDown(Editor* editor, MouseMessage* msg) { // Drawing loop diff --git a/src/app/ui/editor/drawing_state.h b/src/app/ui/editor/drawing_state.h index b75f76c82..279c22095 100644 --- a/src/app/ui/editor/drawing_state.h +++ b/src/app/ui/editor/drawing_state.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2020 Igara Studio S.A. +// Copyright (C) 2019-2021 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of @@ -29,6 +29,7 @@ namespace app { tools::ToolLoop* loop, const DrawingType type); virtual ~DrawingState(); + virtual void onBeforePopState(Editor* editor) override; virtual bool onMouseDown(Editor* editor, ui::MouseMessage* msg) override; virtual bool onMouseUp(Editor* editor, ui::MouseMessage* msg) override; virtual bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override; diff --git a/src/app/ui/editor/moving_cel_state.cpp b/src/app/ui/editor/moving_cel_state.cpp index 5f33ebf83..eed469b46 100644 --- a/src/app/ui/editor/moving_cel_state.cpp +++ b/src/app/ui/editor/moving_cel_state.cpp @@ -112,13 +112,13 @@ MovingCelState::MovingCelState(Editor* editor, else m_celStarts.push_back(cel->bounds()); } - - // Hook BeforeCommandExecution signal so we know if the user wants - // to execute other command, so we can drop pixels. - m_ctxConn = UIContext::instance()->BeforeCommandExecution.connect( - &MovingCelState::onBeforeCommandExecution, this); } + // Hook BeforeCommandExecution signal so we know if the user wants + // to execute other command, so we can drop pixels. + m_ctxConn = UIContext::instance()->BeforeCommandExecution.connect( + &MovingCelState::onBeforeCommandExecution, this); + m_cursorStart = editor->screenToEditorF(msg->position()); editor->captureMouse(); @@ -130,14 +130,10 @@ MovingCelState::MovingCelState(Editor* editor, } } -MovingCelState::~MovingCelState() -{ - m_ctxConn.disconnect(); -} - void MovingCelState::onBeforePopState(Editor* editor) { m_ctxConn.disconnect(); + StandbyState::onBeforePopState(editor); } bool MovingCelState::onMouseUp(Editor* editor, MouseMessage* msg) diff --git a/src/app/ui/editor/moving_cel_state.h b/src/app/ui/editor/moving_cel_state.h index f0b0955f6..509bfba8d 100644 --- a/src/app/ui/editor/moving_cel_state.h +++ b/src/app/ui/editor/moving_cel_state.h @@ -44,7 +44,6 @@ namespace app { ui::MouseMessage* msg, const HandleType handle, const MovingCelCollect& collect); - ~MovingCelState(); virtual void onBeforePopState(Editor* editor) override; virtual bool onMouseUp(Editor* editor, ui::MouseMessage* msg) override; @@ -74,7 +73,7 @@ namespace app { HandleType m_handle; Editor* m_editor; - obs::connection m_ctxConn; + obs::scoped_connection m_ctxConn; }; } // namespace app diff --git a/src/app/ui/editor/play_state.cpp b/src/app/ui/editor/play_state.cpp index d1d9aa293..e4ba6085d 100644 --- a/src/app/ui/editor/play_state.cpp +++ b/src/app/ui/editor/play_state.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2021 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -109,6 +109,12 @@ EditorState::LeaveAction PlayState::onLeaveState(Editor* editor, EditorState* ne return KeepState; } +void PlayState::onBeforePopState(Editor* editor) +{ + m_ctxConn.disconnect(); + StateWithWheelBehavior::onBeforePopState(editor); +} + bool PlayState::onMouseDown(Editor* editor, MouseMessage* msg) { if (editor->hasCapture()) diff --git a/src/app/ui/editor/play_state.h b/src/app/ui/editor/play_state.h index 809092979..cf1751a60 100644 --- a/src/app/ui/editor/play_state.h +++ b/src/app/ui/editor/play_state.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2020 Igara Studio S.A. +// Copyright (C) 2020-2021 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of @@ -32,6 +32,7 @@ namespace app { void onEnterState(Editor* editor) override; LeaveAction onLeaveState(Editor* editor, EditorState* newState) override; + void onBeforePopState(Editor* editor) override; bool onMouseDown(Editor* editor, ui::MouseMessage* msg) override; bool onMouseUp(Editor* editor, ui::MouseMessage* msg) override; bool onMouseMove(Editor* editor, ui::MouseMessage* msg) override; diff --git a/src/observable b/src/observable index af94c4a23..bddbeed8b 160000 --- a/src/observable +++ b/src/observable @@ -1 +1 @@ -Subproject commit af94c4a2317839ce629eb26ce47b80e810cbdaec +Subproject commit bddbeed8b94d2639fa945bdf14a90d7afbd58506