in reply to Re: Getting segfaults when destroying and recreating Tk box
in thread Getting segfaults when destroying and recreating Tk box

Arghhh. Thanks for the tip. It all makes sense now and indeed, the segmentation faults disappear when following your suggested strategy of avoiding destroys.

I note that if you ever destroy a TopLevel window, you eventually provoke another segmentation fault. However if you withdraw the TopLevel windows instead of destroying them, you can go on seemingly indefinitely by withdrawing the old TopLevel window and then defining a subsequent TopLevel window.

Then to exit the MainLoop gracefully, you destroy the original (hidden and withdrawn) MainWindow.

Thanks,
Stefan

  • Comment on Re^2: Getting segfaults when destroying and recreating Tk box

Replies are listed 'Best First'.
Re^3: Getting segfaults when destroying and recreating Tk box
by zentara (Cardinal) on Sep 06, 2007 at 10:43 UTC
    I note that if you ever destroy a TopLevel window, you eventually provoke another segmentation fault.

    That dosn't sound right. You may have a Tk version that needs patching, or you are doing something weird like trying to access a widget packed in the toplevel, after you destroy the toplevel.

    If you want to be happy with Tk, stop using destroy to eliminate windows. To exit gracefully, use plain old "exit" or "Tk::exit", they clean up. If you use $mw->destroy, you may be leaving the calling shell alive. Of course, that may be useful in certain circumstances.

    #!/usr/bin/perl -w use Tk; my $mw = MainWindow->new(-title=>"#1"); $mw->Button(-text=>"Destroy Me", -command=> sub { $mw->destroy })->pack; $mw->Button(-text=>"Exit Me", -command=> sub { Tk::exit })->pack; MainLoop; print "ha ha still going\n"; <>;

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum