From e354c7a59a565387c1135069c8798b4777d826f5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 17 Feb 2014 23:55:17 +0000 Subject: [PATCH] Allow waiting for thread termination even without wxTheApp in wxMSW. Attempts to wait for thread termination after wxTheApp was destroyed resulted in an error in wxMSW since 2.9.something whereas it used to work in 2.8 and also generally makes sense to be allowed. So do make this work again by falling back to the simple non-interruptible wait for thread if we don't have the application object any more. Closes #13391. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@75914 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/thread.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp index 88e696ab34..a2408eb518 100644 --- a/src/msw/thread.cpp +++ b/src/msw/thread.cpp @@ -794,6 +794,8 @@ wxThreadInternal::WaitForTerminate(wxCriticalSection& cs, gs_waitingForThread = true; } + wxAppTraits& traits = wxApp::GetValidTraits(); + // we can't just wait for the thread to terminate because it might be // calling some GUI functions and so it will never terminate before we // process the Windows messages that result from these functions @@ -812,16 +814,9 @@ wxThreadInternal::WaitForTerminate(wxCriticalSection& cs, } } - wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL; - if ( traits ) - { - result = traits->WaitForThread(m_hThread, waitMode); - } - else // can't wait for the thread - { - // so kill it below - result = 0xFFFFFFFF; - } + // Wait for the thread while still processing events in the GUI apps or + // just simply wait for it in the console ones. + result = traits.WaitForThread(m_hThread, waitMode); switch ( result ) { @@ -846,7 +841,7 @@ wxThreadInternal::WaitForTerminate(wxCriticalSection& cs, // the system might dead lock then if ( wxThread::IsMain() ) { - if ( traits && !traits->DoMessageFromThreadWait() ) + if ( !traits.DoMessageFromThreadWait() ) { // WM_QUIT received: kill the thread Kill();