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.
This commit is contained in:
David Capello 2023-12-29 13:18:09 -03:00
parent f178941f2c
commit d8ed4d3995
4 changed files with 27 additions and 10 deletions

View File

@ -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;
}
}

View File

@ -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

View File

@ -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

View File

@ -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: