After all of that, I have 'solved' the problem - but in truth, this is not a solution. The behaviour is bizarre. I'd not have found this without the feedback above - so thankyou - but I'm still at a loss to understand whats going on. Let me describe.

In playing around, I found that I can provoke segmentation faults on my stock-standard Fedora-7 system by simply adding or removing a comment. See below.

#!/usr/bin/perl -w use Tk; use strict; my $MW; my $Array_Index=""; my @Widget_List; my $Abort_Has_Run; MAIN: { debug("+MAIN"); my $my_ref; my @file_references ; my $i; $MW = MainWindow->new; $Abort_Has_Run = 0 ; push @Widget_List, $MW->title("test box 1"); push @Widget_List, $MW->Label(-text=>"Choose one option", -font=>"courierfont") -> pack; @file_references = ("Ref1", "Ref2", "Ref3", "Ref4"); $i=1; foreach $my_ref (@file_references) { push @Widget_List, $MW->Button(-text => "$my_ref", -command => [ \&do_button, "$my_ref,$i"]) -> pack; $i++; } MainLoop(); debug ("-MAIN"); } sub do_button { my $params; my $widget; debug("+do_button"); $params = shift; (my $ref, $Array_Index) = split (/,/,$params); debug("do_button Array_Index: $Array_Index"); # DO SOMETHING USEFUL HERE TO START A PROCESS # $MW->Label(-text=>"This line will cause a segfault") -> pack; foreach $widget (@Widget_List) { $widget->destroy(); } $MW->Button(-text => "Shutdown and close", -command => [ \&abort_routine]) -> pack; $MW->OnDestroy([\&abort_routine]); debug("-do_button"); } sub abort_routine { return if $Abort_Has_Run == 1 ; $Abort_Has_Run = 1 ; debug("+abort_routine"); # DO SOMETHING USEFUL HERE TO CLEAN UP THE PROCESS $MW->destroy(); debug("-abort_routine"); } sub debug { my @msg = shift; print @msg, "\n"; }
If I run the code as above, I repeatedly provoke a segmentation fault. Notice that there is a line which is commented out as such.
# $MW->Label(-text=>"This line will cause a segfault") -> pack;
If I REMOVE the comment on this line, the code DOES NOT segfault. However if I comment the line out, I get a segfault EVERY TIME.

Que? What gives??
Stefan


In reply to Re^6: Getting segfaults when destroying and recreating Tk box by skt
in thread Getting segfaults when destroying and recreating Tk box by skt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.