From 1a18f241bdb52052298892330d9baf8a4925726c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 2 Mar 2008 14:45:41 +0000 Subject: [PATCH] don't post WM_NULL if there is already a WM_NULL in the queue to avoid overflowing it (patch 1904771) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52253 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/app.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 83b8d98d49..04916f784b 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -566,13 +566,28 @@ void wxApp::WakeUpIdle() // start up again. Doing it this way ensures that the idle handler // wakes up in the right thread (see also wxWakeUpMainThread() which does // the same for the main app thread only) - wxWindow *topWindow = wxTheApp->GetTopWindow(); + wxWindow * const topWindow = wxTheApp->GetTopWindow(); if ( topWindow ) { - if ( !::PostMessage(GetHwndOf(topWindow), WM_NULL, 0, 0) ) + HWND hwndTop = GetHwndOf(topWindow); + + // Do not post WM_NULL if there's already a pending WM_NULL to avoid + // overflowing the message queue. + // + // Notice that due to a limitation of PeekMessage() API (which handles + // 0,0 range specially), we have to check the range from 0-1 instead. + // This still makes it possible to overflow the queue with WM_NULLs by + // interspersing the calles to WakeUpIdle() with windows creation but + // it should be rather hard to do it accidentally. + MSG msg; + if ( !::PeekMessage(&msg, hwndTop, 0, 1, PM_NOREMOVE) || + ::PeekMessage(&msg, hwndTop, 1, 1, PM_NOREMOVE) ) { - // should never happen - wxLogLastError(wxT("PostMessage(WM_NULL)")); + if ( !::PostMessage(hwndTop, WM_NULL, 0, 0) ) + { + // should never happen + wxLogLastError(wxT("PostMessage(WM_NULL)")); + } } } } -- 2.45.2