Only drain all pending events when exiting outermost wxEventLoop

This is especially important under MSW, where the modality of the nested
event loops actually ends as soon as wxModalEventLoop::Exit() is called,
and so we must avoid dispatching any events in the current loop after it
happens or we risk reentering the same loop again, which could result in
e.g. parent modal dialog being closed before the child event loop
returns (because the event closing the former was dispatched from the
latter) and other unexpected sequences of events.

To prevent this from happening, only dispatch pending events after the
loop exit if it's the outermost loop, as there should be no danger in
doing it in this case. Conversely, we don't lose anything by not doing
this in nested event loops as the outer loop will take care of any
remaining pending events anyhow.

To make this work in an ABI-compatible way, add a global counter of the
currently existing event loops which is used to check if there is more
than one event loop currently running.

Closes #11273, #11573, #11269.
This commit is contained in:
Vadim Zeitlin
2018-07-04 19:38:10 +02:00
parent cf966718e6
commit a0298f3149
2 changed files with 35 additions and 14 deletions

View File

@@ -63,11 +63,8 @@
class WXDLLIMPEXP_BASE wxEventLoopBase
{
public:
// trivial, but needed (because of wxEventLoopBase) ctor
wxEventLoopBase();
// dtor
virtual ~wxEventLoopBase() { }
virtual ~wxEventLoopBase();
// use this to check whether the event loop was successfully created before
// using it