From f05b626b3b4bb14070205c5f737d2f10f68e1502 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 12 Mar 2015 16:36:48 +0100 Subject: [PATCH] Don't use wxLog from wxWakeUpMainThread() in wxMSW. This can result in infinite recursion as wxLog calls wxWakeUpIdle() which calls wxWakeUpMainThread() again if PostThreadMessage() fails. See #16841. --- src/msw/thread.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp index 06e4da5024..0f2bb413a1 100644 --- a/src/msw/thread.cpp +++ b/src/msw/thread.cpp @@ -27,7 +27,9 @@ #ifndef WX_PRECOMP #include "wx/intl.h" #include "wx/app.h" + #include "wx/log.h" #include "wx/module.h" + #include "wx/msgout.h" #endif #include "wx/apptrait.h" @@ -1417,8 +1419,17 @@ void WXDLLIMPEXP_BASE wxWakeUpMainThread() // sending any message would do - hopefully WM_NULL is harmless enough if ( !::PostThreadMessage(wxThread::GetMainId(), WM_NULL, 0, 0) ) { - // should never happen - wxLogLastError(wxT("PostThreadMessage(WM_NULL)")); + // should never happen, but log an error if it does, however do not use + // wxLog here as it would result in reentrancy because logging from a + // thread calls wxWakeUpIdle() which calls this function itself again + const unsigned long ec = wxSysErrorCode(); + wxMessageOutputDebug().Printf + ( + wxS("Failed to wake up main thread: PostThreadMessage(WM_NULL) ") + wxS("failed with error 0x%08lx (%s)."), + ec, + wxSysErrorMsg(ec) + ); } }