Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: weird case of memory corruption? -- Tk ProgressBar bugged?

by Discipulus (Abbot)
on May 12, 2021 at 09:33 UTC ( #11132458=note: print w/replies, xml ) Need Help??


in reply to Re: weird case of memory corruption?
in thread weird case of memory corruption?

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.

Replies are listed 'Best First'.
Re^3: weird case of memory corruption? -- Tk ProgressBar bugged?
by Marshall (Canon) on May 12, 2021 at 11:04 UTC
    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.
        OK. Your point is accepted and verified by me on Perl v5.24.

        I actually saw this in my testing, but I couldn't believe my own eyes!
        The exact same source code can produce different results when run more than once.

        I am flabbergasted! This is true, but I don't know why or how?

        More Info:
        Updating a Windows GUI is an extremely expensive operation.
        If you have a loop that will do say 10,000 operations, and you want to show progress via a percent or a progress bar, calculate whether or not the progress bar will move before you update the GUI's value - do this at most 100 times (each one percent for a 100% bar) and probably less than that! The difference in performance between calling the GUI 10,000 times vs 100 times is astonishing!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11132458]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2021-09-19 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?