X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4300caa7a669d1e09e7d5dfd739acf4bb08e8b49..331c9f56a44039554ae639b1733ee8ea2022bdd5:/src/msw/evtloop.cpp diff --git a/src/msw/evtloop.cpp b/src/msw/evtloop.cpp index c2540c8ee9..6c7e74c00f 100644 --- a/src/msw/evtloop.cpp +++ b/src/msw/evtloop.cpp @@ -38,7 +38,6 @@ #include "wx/tooltip.h" #include "wx/except.h" #include "wx/ptr_scpd.h" -#include "wx/scopeguard.h" #include "wx/msw/private.h" @@ -241,27 +240,34 @@ int wxEventLoop::Run() wxEventLoopActivator activate(&ms_activeLoop, this); wxEventLoopImplTiedPtr impl(&m_impl, new wxEventLoopImpl); - wxON_BLOCK_EXIT_OBJ0(*this, &wxEventLoop::OnExit); - - for ( ;; ) + // we must ensure that OnExit() is called even if an exception is thrown + // from inside Dispatch() but we must call it from Exit() in normal + // situations because it is supposed to be called synchronously, + // wxModalEventLoop depends on this (so we can't just use ON_BLOCK_EXIT or + // something similar here) + wxTRY { + for ( ;; ) + { #if wxUSE_THREADS - wxMutexGuiLeaveOrEnter(); + wxMutexGuiLeaveOrEnter(); #endif // wxUSE_THREADS - // generate and process idle events for as long as we don't have - // anything else to do - while ( !Pending() && m_impl->SendIdleMessage() ) - ; + // generate and process idle events for as long as we don't have + // anything else to do + while ( !Pending() && m_impl->SendIdleMessage() ) + ; - // a message came or no more idle processing to do, sit in - // Dispatch() waiting for the next message - if ( !Dispatch() ) - { - // we got WM_QUIT - break; + // a message came or no more idle processing to do, sit in + // Dispatch() waiting for the next message + if ( !Dispatch() ) + { + // we got WM_QUIT + break; + } } } + wxCATCH_ALL( OnExit(); ) return m_impl->GetExitCode(); } @@ -272,6 +278,8 @@ void wxEventLoop::Exit(int rc) m_impl->SetExitCode(rc); + OnExit(); + ::PostQuitMessage(rc); }