Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: "Segmentation fault after destroying window"

by mnooning (Beadle)
on Mar 15, 2006 at 21:37 UTC ( #536956=note: print w/replies, xml ) Need Help??

in reply to "Segmentation fault after destroying window"

I am redesigning so that all of the windows are now based on their own
Toplevel, which of course are all off of the one, single MainWindow.
When a window is needed, I will simply use the "Popup" command. Otherwise
the withdraw command will keep it hidden. A small proof of concept
program I have showed it to work.

There will be about 18 windows (some are pretty complicated) that will
be staying in existence througout the life of the program. Most of
the other windows (trivial popups) will use your suggested Dialog.
A lot of extra memory may be taken up by the program, but it should
work. Thanks for the tip.

I am now a little scared to implement the redesign in the real program
at work. It is a pretty big program. I would hate to spend the
couple of weeks needed just to find out it won't work. My fear is
that third party modules that I use, such as Tk::FileSelect, will lead
me to the "Segmentation Fault" because it obviously pops up a
mini-browser, and when done, destroys it.

I notice in the module Fileselect the author uses this call:

Tk::DialogWrapper('fileselect',$cmd, %args);<br>

I could not find any documentation for Tk::DialogWrapper but in
file, sub DialogWrapper has the line

my $w = delete $args{'-parent'};<br>

Further in sub DialogWrapper, this line appears

$w->destroy if $created;<br>


The var $created becomes 1 (and we created a new MainWindow) if $w is
undefined after the afforementioned line. This is important because
it would seem to ruin my chances of success here.

Equally bad, the parameters passed in to DialogWrapper are

my ($method,$kind,%args) = @_;<br>

and I do not know what the parameters are really for, or how to use
them. Nor do I have a clue as to why deleting '-parent' from the
%args hash should cause a new MainWindow to be created.

Is there some documentation that can explain this? I have, and read
most of, Mastering Perl/Tk, but it does not touch upon it. Is there
another book I can purchase that can explain it. Neither google,
dogpile or seemed to help.

I wonder, could it be possible to wrap all third-party modules that
pop up something, cpan or otherwise, in a so-called DialogWrapper?

All this could be avoided if there were just some way to tell if
the $mw->destroy command was really behind-the-scenes finished, so
that when a new MainWindow was needed, my program could be free to
just go ahead and create one. I tried Exists($mw), but Exists passes
sometimes even when the previous $mw->destroy seems done.


Replies are listed 'Best First'.
Re^2: "Segmentation fault after destroying window"
by mnooning (Beadle) on Mar 16, 2006 at 22:37 UTC
    I have another answer I can live with a little easier. I wrote another
    proof of concept script wherein the MainWindow is kept as mentioned before.
    It looks like I can create and destroy Toplevel windows as I need to,
    while keeping the MainWindow withdrawn.

    This works without getting a segmentation fault:

    sub service_for_mw_button_press { my ($mw) = shift; my $top_level = $mw->Toplevel

    and then later, when I no longer need the $top_level,

    $top_level->destroy; undef($top_level); $mw->deiconify; $mw_raise;

    This idea, plus a redesign to make the real program an event driven
    design from the beginning, should do the job. Thanks for all of your

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://536956]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2017-11-24 17:46 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (351 votes). Check out past polls.