From d8ed4d3995b3a7e1ea5a1e2a0f18862d112161d0 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 29 Dec 2023 13:18:09 -0300 Subject: [PATCH] Fix crash if an exception happens in DelayedMouseMove::commitMouseMove() Without this an exception in DelayedMouseMove::commitMouseMove() could produce (e.g.) the crash in #3818. This same error handling was already done for Editor::onProcessMessage() in DocView::onProcessMessage() to avoid crashing due unhandled exceptions in Editor message processing. --- src/app/ui/doc_view.cpp | 10 +--------- src/app/ui/editor/delayed_mouse_move.cpp | 7 ++++++- src/app/ui/editor/editor.cpp | 15 +++++++++++++++ src/app/ui/editor/editor.h | 5 +++++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/app/ui/doc_view.cpp b/src/app/ui/doc_view.cpp index 538eb9803..43532d24e 100644 --- a/src/app/ui/doc_view.cpp +++ b/src/app/ui/doc_view.cpp @@ -167,15 +167,7 @@ protected: return Editor::onProcessMessage(msg); } catch (const std::exception& ex) { - EditorState* state = getState().get(); - - Console console; - Console::showException(ex); - console.printf("\nInternal details:\n" - "- Message type: %d\n" - "- Editor state: %s\n", - msg->type(), - state ? typeid(*state).name(): "None"); + showUnhandledException(ex, msg); return false; } } diff --git a/src/app/ui/editor/delayed_mouse_move.cpp b/src/app/ui/editor/delayed_mouse_move.cpp index 35e362fba..c9a1262c9 100644 --- a/src/app/ui/editor/delayed_mouse_move.cpp +++ b/src/app/ui/editor/delayed_mouse_move.cpp @@ -71,7 +71,12 @@ void DelayedMouseMove::commitMouseMove() if (m_timer.isRunning()) m_timer.stop(); - m_delegate->onCommitMouseMove(m_editor, spritePos()); + try { + m_delegate->onCommitMouseMove(m_editor, spritePos()); + } + catch (const std::exception& ex) { + m_editor->showUnhandledException(ex, nullptr); + } } const gfx::PointF& DelayedMouseMove::spritePos() const diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index e1241021c..8e152b115 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -1897,6 +1897,21 @@ void Editor::cancelSelections() clearSlicesSelection(); } +void Editor::showUnhandledException(const std::exception& ex, + const ui::Message* msg) +{ + EditorState* state = getState().get(); + + Console console; + Console::showException(ex); + console.printf( + "\nInternal details:\n" + "- Message type: %d\n" + "- Editor state: %s\n", + (msg ? msg->type(): -1), + (state ? typeid(*state).name(): "None")); +} + ////////////////////////////////////////////////////////////////////// // Message handler for the editor diff --git a/src/app/ui/editor/editor.h b/src/app/ui/editor/editor.h index e6830c6a7..35c37bff7 100644 --- a/src/app/ui/editor/editor.h +++ b/src/app/ui/editor/editor.h @@ -322,6 +322,11 @@ namespace app { // Properties to show information in the status bar bool showAutoCelGuides() const { return m_showAutoCelGuides; } + // Used in case an unhandled exception was caught when processing + // an Editor or EditorState event. + void showUnhandledException(const std::exception& ex, + const ui::Message* msg); + static void registerCommands(); protected: