in reply to weird case of memory corruption?

I can confirm the weird behaviour.

See Re: TK::ProgressBar Color update which basically says "Don't use ProgressBar, it's buggy." and shows an alternative using Tk::Canvas.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: weird case of memory corruption? -- Tk ProgressBar bugged?
by Discipulus (Canon) on May 12, 2021 at 09:33 UTC
    bravo choroba!

    I simplified the OP example to trap (but only sometimes!!) the bagged behaviour

    #!/usr/bin/perl use Data::Dump; #https://www.perlmonks.org/index.pl?node_id=11132441 use strict; use warnings; use Tk; use Tk::ProgressBar; my %pid=(ex1=>{as=>'temp', val=> -21.5}); my $mw=MainWindow->new(); my $tmpbar=$mw->Frame()->pack( -padx=>30 ); my $pbar = $tmpbar->ProgressBar( -anchor=>'s', -width=>100, -length=>500, -blocks=>100, -gap=>1, -resolution=>0.5, -variable=>\$pid{ex1}{val}, -from=>-30, -to=>70, )->pack(); my $repeat; $repeat = $mw->repeat(500,sub{ $repeat->cancel() if $pid{ex1}{val} > += 65; unless ( defined $pid{ex1}{val} ){ print "WARNING: \$pid{ex1}{val} NO +T FOUND!!\n"; dd %pid; } $pid{ex1}{val}+=5; }); $tmpbar->Label( -textvariable => \$pid{ex1}{val} )->pack(); MainLoop;

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      I ran this code on v5.24 with good looking GUI, but with run time error:
      Use of uninitialized value in numeric ge (>=) at C:\Users\xxxx\Documen +ts\PerlProjects\Monks\node_id=11132441.pl line 31. WARNING: $pid{ex1}{val} NOT FOUND!! ("ex1", { as => "temp", val => undef })
      I am a bit perplexed.

      Update: I changed:

      $repeat->cancel() if $pid{ex1}{val} >= 65; # to the following... $repeat->cancel() if ($pid{ex1}{val} >= 65); and that seems to work better.
        Hello Marshall,

        this is exatcly the point: my code show the bug that happens only sometimes. Try to execute the code many times:

        >perl tkprogressbar2.pl Use of uninitialized value in numeric ge (>=) at tkprogressbar2.pl lin +e 31. WARNING: $pid{ex1}{val} NOT FOUND!! ("ex1", { as => "temp", val => undef }) >perl tkprogressbar2.pl >perl tkprogressbar2.pl >perl tkprogressbar2.pl >perl tkprogressbar2.pl Use of uninitialized value in numeric ge (>=) at tkprogressbar2.pl lin +e 31. WARNING: $pid{ex1}{val} NOT FOUND!! ("ex1", { as => "temp", val => undef })

        L*

        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re^2: weird case of memory corruption?
by perltux (Monk) on May 12, 2021 at 07:44 UTC
    That's a bummer. Thing is I have actually used Tk:ProgressBar previously with no issues, that's why I don't understand why it's misbehaving in this instance, I'm using it the same way as previously.

    Do you think that I should bring this to the attention of the maintainer, Slaven Rezić?
      Creating a bug report is always good. But check first the same issue hasn't been reported already.

      Also, as a workaround, you can set the value after creating the progress bar, e.g.

      my $value = $$val; my $pbar = $$frame->ProgressBar( ... ); $$val = $value;

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]