X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f7550d732256cbbe0d97819bf199e1d943a0590d..f8405d6e6fc2a361d9710dfdaea0b158952803aa:/src/msw/evtloop.cpp diff --git a/src/msw/evtloop.cpp b/src/msw/evtloop.cpp index 7810e76c0b..80be767371 100644 --- a/src/msw/evtloop.cpp +++ b/src/msw/evtloop.cpp @@ -210,7 +210,7 @@ bool wxEventLoopImpl::PreProcessMessage(MSG *msg) bool wxEventLoopImpl::SendIdleMessage() { - return wxTheApp->ProcessIdle(); + return wxTheApp && wxTheApp->ProcessIdle(); } // ============================================================================ @@ -249,40 +249,71 @@ int wxEventLoop::Run() // 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 +#if wxUSE_EXCEPTIONS + for ( ;; ) { - for ( ;; ) + try { -#if wxUSE_THREADS - 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() ) - ; +#endif // wxUSE_EXCEPTIONS - // if the "should exit" flag is set, the loop should terminate but - // not before processing any remaining messages so while Pending() - // returns true, do process them - if ( m_impl->ShouldExit() ) + // this is the event loop itself + for ( ;; ) { - while ( Pending() ) - Dispatch(); - - break; + #if wxUSE_THREADS + 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() ) + ; + + // if the "should exit" flag is set, the loop should terminate + // but not before processing any remaining messages so while + // Pending() returns true, do process them + if ( m_impl->ShouldExit() ) + { + while ( Pending() ) + Dispatch(); + + 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; + } } - // a message came or no more idle processing to do, sit in - // Dispatch() waiting for the next message - if ( !Dispatch() ) +#if wxUSE_EXCEPTIONS + // exit the outer loop as well + break; + } + catch ( ... ) + { + try + { + if ( !wxTheApp || !wxTheApp->OnExceptionInMainLoop() ) + { + OnExit(); + break; + } + //else: continue running the event loop + } + catch ( ... ) { - // we got WM_QUIT - break; + // OnException() throwed, possibly rethrowing the same + // exception again: very good, but we still need OnExit() to + // be called + OnExit(); + throw; } } } - wxCATCH_ALL( OnExit(); ) +#endif // wxUSE_EXCEPTIONS return m_impl->GetExitCode(); }