Is this a potential bug in wxEventLoop

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
bloodlee
Experienced Solver
Experienced Solver
Posts: 77
Joined: Thu Nov 30, 2006 10:49 am
Location: Shenzhen, CHN

Is this a potential bug in wxEventLoop

Post by bloodlee » Thu Sep 10, 2009 8:39 pm

Hi all,
I am facing a strange crash now. (I am using wx 2.8.9 on WinXP).

There is a frame. On that frame, click some button, a modal dialog pops out. Then on that dialog, click other button, another modal dialog pops out. Then quickly close these two dialogs one by one. Then the crash happens. Actually, it's an ASSERT!

It's in the wxwidgets-2.8.9\src\common\evtloopcmn.cpp:154 in the function of wxEventLoopManual::Exit()

Code: Select all

wxCHECK_RET( IsRunning(), _T("can't call Exit() if not running") );
IsRunning() returns false, which means the current event loop is not the modal dialog's loop.

After checking the wx code, I find something maybe the root cause.
Every-time when we create a modal dialog, wx will create a infinite loop for it and disable other toplevel windows. (You can see the source of wxWidgets-2.8.9\src\common\evtloopcmn.cpp, function is wxEventLoop::Run()).

Before starting the loop, wx will switch current active loop using

Code: Select all

wxEventLoopActivator activate(&ms_activeLoop, this);
Then the main thread will enter the dialog's loop.
And in this loop, wx will pend/dispatch events.

When you close the modal dialog (click the X button or something), other top-level windows will be enabled and the modal loop will be ended. wxEventLoopManual::Exit() will be called though event processing and in this function. A flag variable will be set.

Code: Select all

...
m_shouldExit = true;
...
OnExit()
...
Note here: at that time, the loop is not stopped until the code execute at

Code: Select all

int wxEventLoopManual::Run()
{
...
                if ( m_shouldExit )
                {
                    while ( Pending() )
                        Dispatch();

                    break;
                }
...
In this code block, I think that's maybe the root cause of my crash. If I quickly close the two modal dialog. I mean the first close event is handled just but the first modal dialog, but the second close event may be also handled by the first model dialog, since before the first modal dialog's loop ends, it tries to pending (PeekMessage). Then the assert dialog will pop out.

I don't read all code, so this solution is just an assumption.
Is there anyone met this problem before? Any solution to it?

Thanks.

R.U.10
Earned a small fee
Earned a small fee
Posts: 10
Joined: Thu Jun 14, 2007 12:12 pm

Post by R.U.10 » Fri Feb 04, 2011 4:02 pm

I experimented this issue in a similar case with wx 2.9.2:

I have a little modal dialog shown over the main application frame.
This modal dialog is implemented to close (EndModal) itself when the mouse goes outside the window.
An operation in this dialog generates an error with wxLogError.
But to close the error window, the mouse goes outside the little dialog which closes itself and generates the same assertion described above.

I'm quite annoyed by this issue...

cgwahl
In need of some credit
In need of some credit
Posts: 1
Joined: Thu Jan 18, 2018 3:46 pm

Re: Is this a potential bug in wxEventLoop

Post by cgwahl » Thu Jan 18, 2018 3:47 pm

Hello,

I'm also having this same issue. Does anyone know if there is a fix or we are doing something incorrectly?

Thanks!

User avatar
doublemax
Moderator
Moderator
Posts: 15490
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is this a potential bug in wxEventLoop

Post by doublemax » Thu Jan 18, 2018 8:43 pm

If you're still using wx 2.8.x, please try again with wx 3.0.3 or the latest development version. There will be no fixes for 2.8.x.

If it also happens in 3.x, please provide a minimal compilable sample to reproduce the issue.
Use the source, Luke!

Post Reply