[ wxwindows-Patches-1904771 ] MSW: wxEvtHandler::AddPendingEvent overflows message queue

SourceForge.net noreply at sourceforge.net
Sun Mar 2 06:45:43 PST 2008


Patches item #1904771, was opened at 2008-02-29 16:59
Message generated for change (Comment added) made by vadz
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=309863&aid=1904771&group_id=9863

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: MSW specific
Group: bug fix
>Status: Closed
>Resolution: Accepted
Priority: 5
Private: No
Submitted By: Tim Kosse (botg)
Assigned to: Nobody/Anonymous (nobody)
Summary: MSW: wxEvtHandler::AddPendingEvent overflows message queue

Initial Comment:
At some point inside wxEvtHandler::AddPendingEvent, wxApp::WakeUpIdle gets called, which calls ::PostMessage with WM_NULL.

It however does not check if there is already a pending WM_NULL message, which is a problem.

I have attached a patch to the event sample showing this. For every even  custom event, it re-adds the event twice to the list of pending events. As such, the number of pending events is limited to two, yet the message queue of the thread quickly flows over and message will be lost.

While this is an artificial example, this problem does actually occur in real programs, especially if using wxSocket, eventually resulting in lost socket window messages and as such lost socket events causing active connections to hang.

I have tried a few ways to fix this problem, but so far I only came up with one workaround which somewhat works: Check with PeekMessage for pending WM_NULL before posting WM_NULL in wxApp::WakeUpIdle.

The only problem is that PeekMessage cannot be used on WM_NULL only (as that would check all queued messages) but only of a range including WM_NULL, such as 0-1 (WM_CREATE).

So as workaround (see 2nd attached file) I have modified wxApp::WakeUpIdle to only post WM_NULL if there's no queue message in the range 0-1 or a queued WM_CREATE message.
While this still allows overflows, it would require a pretty sophisticated artificial example, I don't believe it can be easily triggered in a real program.

Experimental patch against WX_2_8_BRANCH, should apply against trunk as well.

----------------------------------------------------------------------

Comment By: Vadim Zeitlin (vadz)
Date: 2008-03-02 15:45

Message:
Logged In: YES 
user_id=71618
Originator: NO

Thank you for your patch, it has been applied to both svn trunk and 2.8
branch!

----------------------------------------------------------------------

Comment By: Tim Kosse (botg)
Date: 2008-02-29 16:59

Message:
Logged In: YES 
user_id=156254
Originator: YES

File Added: app.patch

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=309863&aid=1904771&group_id=9863




More information about the wx-dev mailing list