Dialog from dynamic created/destroyed panel crashes python

My aim: walk the user through a work flow. I have a left panel that has steps
1, 2, 3. The right panel is dynamically created and varies depending on the
step. The first step, the user fills out a form that is saved to a file. The
next step uses a file of the user's choice. In the enclosed code (chopped
down from the real code), I build a main panel that contains a left panel
and a dynamic sizer for the right panel. The right panel has a Proceed
button which pulls up the FileDialog. When the dialog exits, the right panel
is destroyed, and python seg faults. (Sometimes it survives one round of
button presses, but crashes on the second.) This happens on both windows 7
64 bit and Linux Mint 17 KDE 64 bit. If I skip the FileDialog, then code
does not crash. I've experienced other seg faults that I figured out was my
fault, but I don't see what I'm doing wrong here. I tried CallAfter in case
there was some issue with Dialogs inside an event, or having the Destory
code called in an event tied to the panel being destroyed, but it doesn't
help.

If anyone can help me understand why I get a seg fault, much appreciated.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Dialog-from-dynamic-created-destroyed-panel-crashes-python-tp5723893.html
Sent from the wxPython-users mailing list archive at Nabble.com.

ggardner wrote:

My aim: walk the user through a work flow. I have a left panel that has steps
1, 2, 3. The right panel is dynamically created and varies depending on the
step. The first step, the user fills out a form that is saved to a file. The
next step uses a file of the user's choice. In the enclosed code (chopped
down from the real code), I build a main panel that contains a left panel
and a dynamic sizer for the right panel. The right panel has a Proceed
button which pulls up the FileDialog. When the dialog exits, the right panel
is destroyed, and python seg faults. (Sometimes it survives one round of
button presses, but crashes on the second.) This happens on both windows 7
64 bit and Linux Mint 17 KDE 64 bit. If I skip the FileDialog, then code
does not crash. I've experienced other seg faults that I figured out was my
fault, but I don't see what I'm doing wrong here. I tried CallAfter in case
there was some issue with Dialogs inside an event, or having the Destory
code called in an event tied to the panel being destroyed, but it doesn't
help.

If anyone can help me understand why I get a seg fault, much appreciated.

Please make a runnable, small as possible, sample application that
demonstrates the problem. MakingSampleApps - wxPyWiki

···

--
Robin Dunn
Software Craftsman

This is as simple as I could make it and still show the problem. This helped
me isolate the cause and come up with a work-around, so thanks for that
push, but I think there still may be a problem to report. Note in this
version, on line 55, if self.right is replaced with None or some other
parent, then there is no seg fault. But I think (in my ignorance, perhaps) I
should be able to destroy the dialog in self.right before I destroy
self.right without a problem, especially if the second destroy is in a
CallAfter. To use, click 'Go' which creates the dynamic right panel, then
Return and (Save or Cancel). You should get a seg fault. Thanks for your
attention.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Dialog-from-dynamic-created-destroyed-panel-crashes-python-tp5723893p5723987.html
Sent from the wxPython-users mailing list archive at Nabble.com.

ggardner wrote:

This is as simple as I could make it and still show the problem. This helped
me isolate the cause and come up with a work-around, so thanks for that
push, but I think there still may be a problem to report. Note in this
version, on line 55, if self.right is replaced with None or some other
parent, then there is no seg fault. But I think (in my ignorance, perhaps) I
should be able to destroy the dialog in self.right before I destroy
self.right without a problem, especially if the second destroy is in a
CallAfter. To use, click 'Go' which creates the dynamic right panel, then
Return and (Save or Cancel). You should get a seg fault. Thanks for your
attention.

There isn't any code attached.

···

--
Robin Dunn
Software Craftsman

Hi Robin,

(Not the original poster, but …)

The code is at the nabble link. Dunno why it didn’t get transferred to the mailing list.

http://wxpython-users.1045709.n5.nabble.com/Dialog-from-dynamic-created-destroyed-panel-crashes-python-tp5723893p5723987.html

HTH.

Cheers,

Scott.

···

On Tue, Apr 7, 2015 at 3:35 PM, Robin Dunn robin@alldunn.com wrote:

This is as simple as I could make it and still show the problem. This helped

me isolate the cause and come up with a work-around, so thanks for that

push, but I think there still may be a problem to report. Note in this

version, on line 55, if self.right is replaced with None or some other

parent, then there is no seg fault. But I think (in my ignorance, perhaps) I

should be able to destroy the dialog in self.right before I destroy

self.right without a problem, especially if the second destroy is in a

CallAfter. To use, click ‘Go’ which creates the dynamic right panel, then

Return and (Save or Cancel). You should get a seg fault. Thanks for your

attention.
ggardner wrote:

There isn’t any code attached.

Robin Dunn

Software Craftsman

http://wxPython.org

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

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

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

Robin Dunn wrote

There isn't any code attached.
--
Robin Dunn
Software Craftsman
http://wxPython.org

As grunculus pointed out (thanks!), I embedded the file using raw,/raw html
tags, not seeing it wasn't in the email, since I'm using the nabble.com web
interface. (I signed up with a personal email account in case I wanted to
wxpython outside of work, but this is work and I don't read my personal
email at work.) It looked complete at the web site, so I assumed it was in
the email as well.

Attaching the file now.
z4.py <http://wxpython-users.1045709.n5.nabble.com/file/n5724003/z4.py&gt;

Regards,
Glenn

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Dialog-from-dynamic-created-destroyed-panel-crashes-python-tp5723893p5724003.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Hi Glenn,

I think this is because the File Save dialog is child of dynamic panel you are trying to create (self.right). Upon executing Return method where you destroy the panel and there after you try to destroy the dialog. AFAIK if you destroy panel all the children associated with the panel will also be destroyed. Which is why your attempt to destroy dialog is failing and resulting in python crash.

When i tried below i did not see any crash. I moved dlg to be child of Frame instead of panel.

def onReturnButton(self, event):

XXX: works if given None or some other parent.

dlg = wx.FileDialog(self, message=“Save”,

defaultDir=‘.’, style=wx.SAVE)

I may not be 100% correct. This is just my hypothesis.

Thanks,

Saurabh

···

On Wednesday, 8 April 2015 07:35:17 UTC-7, glenngard wrote:

Robin Dunn wrote

There isn’t any code attached.


Robin Dunn

Software Craftsman

http://wxPython.org

As grunculus pointed out (thanks!), I embedded the file using raw,/raw html

tags, not seeing it wasn’t in the email, since I’m using the nabble.com web

interface. (I signed up with a personal email account in case I wanted to

wxpython outside of work, but this is work and I don’t read my personal

email at work.) It looked complete at the web site, so I assumed it was in

the email as well.

Attaching the file now.

z4.py <http://wxpython-users.1045709.n5.nabble.com/file/n5724003/z4.py>

Regards,

Glenn

View this message in context: http://wxpython-users.1045709.n5.nabble.com/Dialog-from-dynamic-created-destroyed-panel-crashes-python-tp5723893p5724003.html

Sent from the wxPython-users mailing list archive at Nabble.com.

ggardner wrote:

Robin Dunn wrote

There isn't any code attached.
--
Robin Dunn
Software Craftsman
http://wxPython.org

As grunculus pointed out (thanks!), I embedded the file using raw,/raw html
tags, not seeing it wasn't in the email, since I'm using the nabble.com web
interface. (I signed up with a personal email account in case I wanted to
wxpython outside of work, but this is work and I don't read my personal
email at work.) It looked complete at the web site, so I assumed it was in
the email as well.

Attaching the file now.
z4.py<http://wxpython-users.1045709.n5.nabble.com/file/n5724003/z4.py&gt;

When the dialog exits, the right panel
is destroyed, and python seg faults. (Sometimes it survives one round of
button presses, but crashes on the second.) This happens on both windows 7
64 bit and Linux Mint 17 KDE 64 bit. If I skip the FileDialog, then code
does not crash. I've experienced other seg faults that I figured out was my
fault, but I don't see what I'm doing wrong here. I tried CallAfter in case
there was some issue with Dialogs inside an event, or having the Destory
code called in an event tied to the panel being destroyed, but it doesn't
help.

You were on the right track. The Destroy method of dialogs and frames automatically defer the actual destruction until there are no more pending events. But since wx.CallAfter is implemented by posting an event to the pending event queue then your self.onReturn method is still going to be called before the file dialog is destroyed because the queue will not be empty until after the CallAfter event is processed. If you change the wx.CallAfter to a wx.CallLater (which uses a timer instead of the pending event queue) then it will give the system time to process pending events and destroy the dialog before it tries running onReturn.

OTOH, I tend to use the top level parent for parenting dialogs rather than some child window. One of the platforms (I forget which) requires that dialogs be parented by a top-level window and wx takes care of that internally for you at the native level when the dialog is created. But I figure that it's better that my containment hierarchy matches the reality of what is being done on the system, so I would use self in your example, or self.GetTopLevelParent() if self is not a frame.

···

--
Robin Dunn
Software Craftsman

Robin Dunn wrote

ggardner wrote:

Robin Dunn wrote

There isn't any code attached.
--
Robin Dunn
Software Craftsman
http://wxPython.org

As grunculus pointed out (thanks!), I embedded the file using raw,/raw
html
tags, not seeing it wasn't in the email, since I'm using the nabble.com
web
interface. (I signed up with a personal email account in case I wanted to
wxpython outside of work, but this is work and I don't read my personal
email at work.) It looked complete at the web site, so I assumed it was
in
the email as well.

Attaching the file now.
z4.py&lt;http://wxpython-users.1045709.n5.nabble.com/file/n5724003/z4.py&gt;

When the dialog exits, the right panel
is destroyed, and python seg faults. (Sometimes it survives one round of
button presses, but crashes on the second.) This happens on both windows
7
64 bit and Linux Mint 17 KDE 64 bit. If I skip the FileDialog, then code
does not crash. I've experienced other seg faults that I figured out was
my
fault, but I don't see what I'm doing wrong here. I tried CallAfter in
case
there was some issue with Dialogs inside an event, or having the Destory
code called in an event tied to the panel being destroyed, but it doesn't
help.

You were on the right track. The Destroy method of dialogs and frames
automatically defer the actual destruction until there are no more
pending events. But since wx.CallAfter is implemented by posting an
event to the pending event queue then your self.onReturn method is still
going to be called before the file dialog is destroyed because the queue
will not be empty until after the CallAfter event is processed. If you
change the wx.CallAfter to a wx.CallLater (which uses a timer instead of
the pending event queue) then it will give the system time to process
pending events and destroy the dialog before it tries running onReturn.

OTOH, I tend to use the top level parent for parenting dialogs rather
than some child window. One of the platforms (I forget which) requires
that dialogs be parented by a top-level window and wx takes care of that
internally for you at the native level when the dialog is created. But
I figure that it's better that my containment hierarchy matches the
reality of what is being done on the system, so I would use self in your
example, or self.GetTopLevelParent() if self is not a frame.

--
Robin Dunn
Software Craftsman
http://wxPython.org

Robin,

Thanks for your explanation. I see in the wxWidget class hierarchy that
Dialog and Frame both inherit from TopLevelWindow which inherits from
NonOwnedWindow, while Panel (what launches the FileDialog in my real code)
inherits from Window. I suppose destruction is delayed for Dialog and Frame
because, being TopLevel and NonOwned, they need to let the events of
everything owned by them be processed before tearing down the tree.

Thanks,
Glenn

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Dialog-from-dynamic-created-destroyed-panel-crashes-python-tp5723893p5724006.html
Sent from the wxPython-users mailing list archive at Nabble.com.