Silent crash on widget.Destroy()

I’m using wxPython 2.8.9.2-1, python 2.6, on an Arch Linux.
The background:
I’m trying to create a small app that sits on the bottom of the screen, occupying the whole display width. This big bar is divided in (and composed by) one or more slightly modified TextCtrls, each one fitting it’s own text and the last one expading to the end. So it looks like this:

GUITest.py (3.48 KB)

···

text here | some other text here | finally some more |


Initially there’s only one entry, but every time the user presses “TAB”, the last widget fits it’s text and a new one is created. And for each “ESC” pressed, the last widget is destroyed.


blah | --press tab–> | blah | new! | --press esc–> | blah |


The problem:
The code is a bit confusing, but it’s mostly working. The problem arrives when the user deletes an entry by pressing ESC: it generates a simple, silent crash.
When the “argument.Destroy()” method is called by the user, at the end of the code everything disappears and just a “Exit code: 0 Signal: 11” lasts. But if the building code calls this function, everything goes smooth.

I have tried removing any events linked to this object and detatching it from the sizer, but nothing changes.

The shrinked code is attached.

Sorry for the confusing descriptions, but I can’t understand it myself. What is happening?

Lucas Boppre Niehues wrote:

I'm using wxPython 2.8.9.2-1, python 2.6, on an Arch Linux.

The background:

I'm trying to create a small app that sits on the bottom of the screen, occupying the whole display width. This big bar is divided in (and composed by) one or more slightly modified TextCtrls, each one fitting it's own text and the last one expading to the end. So it looks like this:

----------------------------------------------------------------------
> text here | some other text here | finally some more |
----------------------------------------------------------------------

Initially there's only one entry, but every time the user presses "TAB", the last widget fits it's text and a new one is created. And for each "ESC" pressed, the last widget is destroyed.

------------------- ------------------- -------------------
> blah | --press tab--> | blah | new! | --press esc--> | blah |
------------------- ------------------- -------------------

The problem:

The code is a bit confusing, but it's mostly working. The problem arrives when the user deletes an entry by pressing ESC: it generates a simple, silent crash.

When the "argument.Destroy()" method is called *by the user*, *at the end of the code* everything disappears and just a "Exit code: 0 Signal: 11" lasts. But if the building code calls this function, everything goes smooth.

I have tried removing any events linked to this object and detatching it from the sizer, but nothing changes.

The shrinked code is attached.

Sorry for the confusing descriptions, but I can't understand it myself. What is happening?

I assume you're adding and deleting controls from a sizer. I think the proper way to do that is to use sizer.Remove(). If you plan to keep the widget around, then sizer.Detach() is what you won't as it will remove the widget, but not destroy it (thus making it available for re-insertion).

Mike

Thanks, but both of them do the same thing on my code: absolutely nothing. I think it adds to the mystery of the case.

Hello,

···

On Thu, Mar 12, 2009 at 4:20 PM, Lucas Boppre Niehues lucasboppre@gmail.com wrote:

Thanks, but both of them do the same thing on my code: absolutely nothing. I think it adds to the mystery of the case.


wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

The problem is actually in your OnKey event handler. When you Skip the event after the object it belongs to has been deleted is where the crash is happening.

I am just guessing but the event handling under the hood must be trying to access some deleted memory and is causing the crash. If you avoid calling on the event object after deleting the control there are no more crashes.

Cody

Thank you very much Cody.

I will try to mess with some “event.Skip” positioning, just to not simple drop it.

Lucas Boppre Niehues wrote:

Thank you very much Cody.

I will try to mess with some "event.Skip" positioning, just to not simple drop it.

Try doing it like this:

  widget.Hide()
  wx.CallAfter(widget.Destroy)
  self.Layout() # or whatever you do to change sizes

The Hide will make the widget not be considered by the sizer for layout, and delaying the Destroy with CallAfter will ensure that there are no pending events for the widget after it is destroyed (by virtue of the fact that Destroy is not called until there are no more events.)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!