From 4750e1ee78f9256519c80596aeb76dbbbf7b7582 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 17 Jan 2018 11:47:08 +0100 Subject: [PATCH] Exit the main loop, not the current one, on unhandled exception If wxApp::OnExceptionInMainLoop() returns false, we're supposed to exit the application by stopping its main event loop, not the loop that is currently running, so do the former instead of the latter. Also call wxAbort() if we can't exit the application in any other way, this is not ideal, but still better than not doing anything and, for example, keeping showing the same "Unexpected error occurred" message box to the user over and over again if the exception comes from an event handler being called repeatedly, such as wxEVT_PAINT or wxEVT_IDLE. --- src/common/event.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/common/event.cpp b/src/common/event.cpp index d32a21d9d6..867871a348 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -1635,8 +1635,21 @@ void wxEvtHandler::WXConsumeException() { if ( !wxTheApp || !wxTheApp->OnExceptionInMainLoop() ) { - if ( loop ) - loop->Exit(); + // If OnExceptionInMainLoop() returns false, we're supposed to exit + // the program and for this we need to exit the main loop, not the + // possibly nested one we're running right now. + if ( wxTheApp ) + { + wxTheApp->ExitMainLoop(); + } + else + { + // We must not continue running after an exception, unless + // explicitly requested, so if we can't ensure this in any + // other way, do it brutally like this. + wxAbort(); + } + } //else: continue running current event loop }