mnooning has asked for the wisdom of the Perl Monks concerning the following question:
I have a segmentation fault problem on more than one Linux variant. I
have gathered information about my problem from searching and visiting
from the URL
http://rt.cpan.org/Public/Bug/Display.html?id=16053
and some others that had to do with
"Segmentation fault after destroying non-dependent window"
The comments at those sites make it apparent that I am going about what
I do in the wrong way.
In essense, my old code has a while loop wherein I call a main menu,
amongst other things. From the main menu I get back one of many
possible choices. Each choice may or may not call other subroutines
that may or may not each invoke there own Tk pop ups. Each pop up has
it's own main window, and it's own MainLoop. When the user clicks an
"Okay" button on the popups, the main window is destroyed and I
eventually get back to the original while loop. While this works fine
on Windows, it causes segmentation faults in a number of Linux
variants. It is the equivalent of having the code below:
my $count = 0; my $message = "Get a Segmentation fault within 20 clicks of Okay: "; my $answer = "Okay"; while ($answer eq "okay") { pop_up_a_message($message . $count); $answer = return_exit_if_count_gt_5($count++); }
I tried a simple redesign wherein I first instantiate a MainWindow
($mw), hiding it right away. I changed the routine
pop_up_a_message to send in $mw as well as the $message, and within
pop_up_a_message I have the statement
$we_top = $mw->Toplevel();
I then use $we_top to instantiate the pop up Label (which has the
message) and an "Okay" button. When the user clicks the Okay button
in my pop_up_a_message() routine, $we_top gets destroyed and the
pop_up_a_message() routine returns.
At first I had the "MainLoop;" in the pop_up_a_message() routine. I
forgot that it would not work because even though $we_top was
destroyed when the user clicked the Okay button, the MainWindow was
still alive, and hence would not get past the Mainloop of the
pop_up_a_message() routine. I next moved the MainLoop statement to
after the end of the while loop. I immediately got 5 pop ups, so that
would not work either.
I then moved the "MainLoop;" statement to be the last statement within
the while loop. I got the first pop up, but then no more since $mw is
still alive. It will not get past the MainLoop.
So ... how does one be able to have a program with pop ups at
different times, in different places, given widely varying user
responses. A lot of these popups have Yes/No and other answers that
need to get returned.
Just to be complete, the segmentation fault code that I posted on the
other forums is shown below.
#!/usr/bin/perl -w # File test_pop_up_a_message.pl use Tk; use strict; our $answer = "okay"; ############ sub response { my ($we_top, $button_response) = @_; $we_top->destroy; $answer = $button_response; } ############ sub pop_up_a_message { my ($message) = @_; my $okay_button; my $exit_button; print("Can allways see\n"); my $we_top = new MainWindow; print("Cannot see if Segmentation fault\n"); $we_top->Label ( -text => $message)->pack(); #......... $okay_button = $we_top->Button( -text => 'Okay', -command => [ \&response, $we_top, 'okay' ] )->pack(); #......... $exit_button = $we_top->Button( -text => 'Exit', -command => [ \&response, $we_top, 'exit' ] )->pack(); #......... $we_top->MainLoop; } ############ my $message = ""; my $count = 1; while ($answer eq "okay") { $message = "On at least Slackware and Mandriva, Perl 5.8.7 or 5.8.8, this code +will\n" . " get a Segmentation fault within 20 clicks of Okay \n " . $count++ . "\n"; pop_up_a_message($message); print ("You pressed $answer\n"); }
Thanks
Edited by planetscape - added readmore tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: "Segmentation fault after destroying window"
by zentara (Cardinal) on Mar 07, 2006 at 21:38 UTC | |
|
Re: "Segmentation fault after destroying window"
by mnooning (Beadle) on Mar 15, 2006 at 21:37 UTC | |
by mnooning (Beadle) on Mar 16, 2006 at 22:37 UTC |