Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I run both Linux Mandrake (Perl 5.8.6) and Windows XP (also Perl 5.8.6) and I get the same error (and crash) on both when using the perl debugger. But only when using the perl debugger. Otherwise it runs just fine.

I was trying to use the perl debugger to trace to an unrelated problem in a rather large program. After considerable shuffling I came up with the short script below that brings out the problem on both platforms.

If I can solve this, I can go back to using the debugger with my real program.
Thanks
use Tk; use Tk::ProgressBar; my $percent_done = 0; my $i = 0; our $mw = MainWindow->new(-title => 'ProgressBar example'); my $progress = $mw->ProgressBar( -variable => \$percent_done )->pack(- +fill => 'x'); $mw->Button(-text => 'Go!', -command=> sub { for ($i = 0; $i < 1000; $i++) { $percent_done = $i/10; $mw->update; # otherwise we don't see how far we are. } })->pack(-side => 'bottom'); $mw->Button(-text => 'Exit!', -command=> sub {$mw->destroy;} )->pack(-side => 'bottom'); MainLoop;

2005-04-06 Janitored by Arunbear - added code tags, as per Monastery guidelines

Replies are listed 'Best First'.
Re: Bizarre copy of ARRAY in leave at ...
by NateTut (Deacon) on Apr 06, 2005 at 21:01 UTC
    Not that it helps much but it crashes for me as well (Perl 5.8 on Win XP):

    Tk::Error: Can't set -variable to `SCALAR(0x18299b4)' for Tk::ProgressBar=HASH(0
    x4e044f4): Bizarre copy of ARRAY in leave at C:/Perl/site/lib/Tk/Trace.pm line 8
    9.
     at C:/Perl/site/lib/Tk/Derived.pm line 294
     Tk callback for event
     Tk callback for .
     Tk callback for .progressbar
     Tk::Derived::configure at C:/Perl/site/lib/Tk/Derived.pm line 306
     Tk::Widget::new at C:/Perl/site/lib/Tk/Widget.pm line 205
     Tk::Widget::__ANON__C:/Perl/site/lib/Tk/Widget.pm:256 at C:/Perl/site/lib/Tk/
    Widget.pm line 256
    Can't set -variable to `SCALAR(0x18299b4)' for Tk::ProgressBar=HASH(0x4e044f4):
    Bizarre copy of ARRAY in leave at C:/Perl/site/lib/Tk/Trace.pm line 89.
     at C:/Perl/site/lib/Tk/Derived.pm line 294
    
     at C:/Perl/site/lib/Tk/Derived.pm line 306
     error:Bizarre copy of ARRAY in leave at C:/Perl/site/lib/Tk/Trace.pm line 89.
    
      I was able to get the thing to at least run ... until I hit the Exit or Go buttons. The problem seems to be that the
      ProgressBar code works with undefined items, and just ignores the errors, while the debugger does not ignore them.
      The case in point is ProgressBar::variable
      I will paste the original, that crashes in the debugger, and my fix.
      sub variable { my $c = shift; my $oldvarref = $c->{'-variable'}; my $oldval = $$oldvarref if $oldvarref; if(@_) { my $varref = shift; if ($oldvarref) { $c->traceVdelete($oldvarref); } $c->{'-variable'} = $varref; $c->traceVariable($varref, 'w', sub { $c->value($_[1]) }); $$varref = $oldval; _layoutRequest($c,2); } $oldval; } <\code> <br> Here is the fix<br> <br> <code> sub variable { my $c = shift; my $oldvarref = ""; my $oldval = ""; if (defined($c->{'-variable'})) { $oldvarref = $c->{'-variable'}; $oldval = $$oldvarref if $oldvarref; } if(@_) { my $varref = shift; $c->traceVdelete($oldvarref) if (defined($oldvarref) and ($oldvarref ne "")); $c->{'-variable'} = $varref; $c->traceVariable($varref, 'w', sub { $c->value([1]) }); $$varref = $oldval if (defined($oldval) and ($oldval ne "")); _layoutRequest($c,2); } return ($oldval) if (defined($oldval) and ($oldval ne "")); }


      This took way to long for me to find. Now I have a worse problem (again, only in the debugger).
      It runs in that it pops up the progress bar, but when I click on either Exit or Go, it bombs.
      I have traced it down to Tk::MainLoop where it does

      DoOneEvent(0);

      but I cannot trace from there. I am getting very nervous that Tk may have such unprotected
      undefined items sprinkled about. That would spell doom for anyone wanting to use Tk ... and be
      able to use the Perl debugger.

      Someone ... please say it isn't so!
      Thanks