pushing handlers, then forgetting to pop them, asserts in Phoenix

Hello,
I’ve just found out that this will trigger an assert in Phoenix, when destroying the window:

`class MyEvtHandler(wx.EvtHandler):
def init(self):
wx.EvtHandler.init(self)
self.Bind(wx.EVT_BUTTON, self.on_clic)

def on_clic(self, evt):
    print("hello!")
    evt.Skip()

class MainFrame(wx.Frame):
def init(self, *a, **k):
wx.Frame.init(self, *a, **k)
button = wx.Button(self)
button.PushEventHandler(MyEvtHandler())`

Now when you close the window you get an AssertionError. Apparently, we hit this assert in wxWidgets, checking that “Any additional event handlers should be popped before the window is deleted”.
Which is fine, except that I can’t remember wxPython Classic ever complaining about this. Maybe the old machinery did a better job at cleaning up? Or I always been lucky and never experienced a crash because of an orphan handler?

riccardo

wrote:

Hello,
I’ve just found out that this will trigger an assert in Phoenix, when destroying the window:

`class MyEvtHandler(wx.EvtHandler):
def init(self):
wx.EvtHandler.init(self)
self.Bind(wx.EVT_BUTTON, self.on_clic)

def on_clic(self, evt):
    print("hello!")
    evt.Skip()

class MainFrame(wx.Frame):

def init(self, *a, **k):
wx.Frame.init(self, *a, **k)
button = wx.Button(self)
button.PushEventHandler(MyEvtHandler())`

Now when you close
the window you get an AssertionError. Apparently, we hit this
assert in wxWidgets
, checking that “Any additional event handlers should be popped before the window is deleted”.
Which is fine, except that I can’t remember wxPython Classic ever complaining about this. Maybe the old machinery did a better job at cleaning up? Or I always been lucky and never experienced a crash because of an orphan handler?

Probably just lucky. The assert wasn’t there until sometime in the 2.9 release series, IIRC. I’ve helped fix issues related to it in projects using wxPython Classic 3.0.x so I know there wasn’t anything hiding or protecting you from the assert in Classic. (Unless perhaps you were using a build that had assertions turned off.)

···

riccardo.polignieri@gmail.com

Robin Dunn

Software Craftsman

http://wxPython.org

Ok thanks.
At the moment even the most recent version of wxPython Classic (3.0.2.0) does not assert. Maybe one day Classic will do too…

r

···

Il giorno giovedì 20 luglio 2017 02:17:21 UTC+2, Robin Dunn ha scritto:

riccardo....@gmail.com
wrote:

Hello,
I’ve just found out that this will trigger an assert in Phoenix, when destroying the window:

`class MyEvtHandler(wx.EvtHandler):
def init(self):
wx.EvtHandler.init(self)
self.Bind(wx.EVT_BUTTON, self.on_clic)

def on_clic(self, evt):
    print("hello!")
    evt.Skip()

class MainFrame(wx.Frame):

def init(self, *a, **k):
wx.Frame.init(self, *a, **k)
button = wx.Button(self)
button.PushEventHandler(MyEvtHandler())`

Now when you close
the window you get an AssertionError. Apparently, we hit this
assert in wxWidgets
, checking that “Any additional event handlers should be popped before the window is deleted”.
Which is fine, except that I can’t remember wxPython Classic ever complaining about this. Maybe the old machinery did a better job at cleaning up? Or I always been lucky and never experienced a crash because of an orphan handler?

Probably just lucky. The assert wasn’t there until sometime in the 2.9 release series, IIRC. I’ve helped fix issues related to it in projects using wxPython Classic 3.0.x so I know there wasn’t anything hiding or protecting you from the assert in Classic. (Unless perhaps you were using a build that had assertions turned off.)


Robin Dunn

Software Craftsman

http://wxPython.org