aui based programm terminates with assertion error

Hi,

I am rewriting a large application to use wx.aui. It works very well but upon terminating I get an assertion error:

File “/Users/ck/devel/peak-o-mat/branches/aui/peak_o_mat/mainframe.py”, line 254, in start
wx.GetApp().MainLoop()
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/wx/core.py”, line 2134, in MainLoop
rv = wx.PyApp.MainLoop(self)
wx._core.wxAssertionError: C++ assertion “GetEventHandler() == this” failed at /Users/robind/projects/buildbots/macosx-vm6/dist-osx-py37/Phoenix/ext/wxWidgets/src/common/wincmn.cpp(478) in ~wxWindowBase(): any pushed event handlers must have been removed

``

This happens on both OSX and MSW but on the latter in addition python crashes.

python3.7, wxpython-4.0.4

What does that message mean? Have I take care of removing those event handlers by myself? And if yes, how?

Regards, Chrsitian

The assertion happens because the C++ wxAuiManager::SetManagedWindow does this:

m_frame->PushEventHandler(this);

but there is no corresponding PopEventHandler in the AUI code.

You can probably avoid the assertion by adding a EVT_CLOSE handler for the Frame passed to SetManagedWindow that does something like this:

self.PopEventHandler(True)

event.Skip()

If something besides a Frame is the managed window then you’ll need to adapt to that configuration.

···

On Monday, January 21, 2019 at 10:06:18 AM UTC-8, ckkart@gmail.com wrote:

Hi,

I am rewriting a large application to use wx.aui. It works very well but upon terminating I get an assertion error:

File “/Users/ck/devel/peak-o-mat/branches/aui/peak_o_mat/mainframe.py”, line 254, in start
wx.GetApp().MainLoop()
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/wx/core.py”, line 2134, in MainLoop
rv = wx.PyApp.MainLoop(self)
wx._core.wxAssertionError: C++ assertion “GetEventHandler() == this” failed at /Users/robind/projects/buildbots/macosx-vm6/dist-osx-py37/Phoenix/ext/wxWidgets/src/common/wincmn.cpp(478) in ~wxWindowBase(): any pushed event handlers must have been removed

``

This happens on both OSX and MSW but on the latter in addition python crashes.

python3.7, wxpython-4.0.4

What does that message mean? Have I take care of removing those event handlers by myself? And if yes, how?

Robin

Thanks Robin. That helped.

···

El lunes, 21 de enero de 2019, 16:55:35 (UTC-3), Robin Dunn escribió:

On Monday, January 21, 2019 at 10:06:18 AM UTC-8, ckk...@gmail.com wrote:

Hi,

I am rewriting a large application to use wx.aui. It works very well but upon terminating I get an assertion error:

File “/Users/ck/devel/peak-o-mat/branches/aui/peak_o_mat/mainframe.py”, line 254, in start
wx.GetApp().MainLoop()
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/wx/core.py”, line 2134, in MainLoop
rv = wx.PyApp.MainLoop(self)
wx._core.wxAssertionError: C++ assertion “GetEventHandler() == this” failed at /Users/robind/projects/buildbots/macosx-vm6/dist-osx-py37/Phoenix/ext/wxWidgets/src/common/wincmn.cpp(478) in ~wxWindowBase(): any pushed event handlers must have been removed

``

This happens on both OSX and MSW but on the latter in addition python crashes.

python3.7, wxpython-4.0.4

What does that message mean? Have I take care of removing those event handlers by myself? And if yes, how?

The assertion happens because the C++ wxAuiManager::SetManagedWindow does this:

m_frame->PushEventHandler(this);

but there is no corresponding PopEventHandler in the AUI code.

You can probably avoid the assertion by adding a EVT_CLOSE handler for the Frame passed to SetManagedWindow that does something like this:

self.PopEventHandler(True)

event.Skip()

If something besides a Frame is the managed window then you’ll need to adapt to that configuration.

Robin

AuiManager has a UnInit method which should be called before a managed frame or
window is destroyed.

See:

https://docs.wxpython.org/wx.lib.agw.aui.framemanager.AuiManager.html#wx.lib.agw.aui.framemanager.AuiManager.UnInit

Yep, unfortunately the wx.aui implementation doesn’t have that method. Although now that I think about it I could probably graft it on…

···

On Tuesday, January 22, 2019 at 8:48:08 AM UTC-8, Torsten wrote:

AuiManager has a UnInit method which should be called before a managed frame or
window is destroyed.

See:

https://docs.wxpython.org/wx.lib.agw.aui.framemanager.AuiManager.html#wx.lib.agw.aui.framemanager.AuiManager.UnInit

Robin

Oops, it looks like it is there now. :slight_smile:

···

On Tuesday, January 22, 2019 at 9:51:49 AM UTC-8, Robin Dunn wrote:

On Tuesday, January 22, 2019 at 8:48:08 AM UTC-8, Torsten wrote:

AuiManager has a UnInit method which should be called before a managed frame or
window is destroyed.

See:

https://docs.wxpython.org/wx.lib.agw.aui.framemanager.AuiManager.html#wx.lib.agw.aui.framemanager.AuiManager.UnInit

Yep, unfortunately the wx.aui implementation doesn’t have that method. Although now that I think about it I could probably graft it on…

Robin

I was going to say, I’ve been using it for a couple years. :slight_smile:

def Destroy(self):

“”" If anyone has created a MainWindow, then we must make absolutely

sure that the AUIManager is disconnected before the application

terminates, so call UnInit here and in an exit handler.

“”"

if self.aui is None:

return 0

self.Closing() # Callback to user actions.

self.aui.UnInit()

return super().Destroy()

···

On Tue, Jan 22, 2019 at 9:53 AM Robin Dunn robin@alldunn.com wrote:

On Tuesday, January 22, 2019 at 9:51:49 AM UTC-8, Robin Dunn wrote:

On Tuesday, January 22, 2019 at 8:48:08 AM UTC-8, Torsten wrote:

AuiManager has a UnInit method which should be called before a managed frame or
window is destroyed.

See:

https://docs.wxpython.org/wx.lib.agw.aui.framemanager.AuiManager.html#wx.lib.agw.aui.framemanager.AuiManager.UnInit

Yep, unfortunately the wx.aui implementation doesn’t have that method. Although now that I think about it I could probably graft it on…

Oops, it looks like it is there now. :slight_smile:

Robin

You received this message because you are subscribed to the Google Groups “wxPython-dev” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Right, that works, too. And looks like the cleaner way.

Thanks.