Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: weird case of memory corruption? -- Tk -textvariable

by Discipulus (Canon)
on May 12, 2021 at 06:56 UTC ( [id://11132444]=note: print w/replies, xml ) Need Help??


in reply to weird case of memory corruption?

Hello perltux,

..really weird :) Firstly I removed all stringified numbers, all STDOUT explicit mention and implicit hash element access.. not the cause of your errors but just to clean the field.

Then I suspect the problem being in the -textvariable behaviour: I suspect problem accessing elements of a nested datastructure. Infact uncommenting my DUMMY assignement I found sometimes val being undef (using dd to dump the whole hash)

#!/usr/bin/perl use Data::Dump; 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 $dummy = 'DUMMY'; # my $dummy = $pid{ex1}->{val}; PBar( $tmpbar, \$dummy, -30, 70 )->pack(); # PBar( $tmpbar, \$pid{ex1}->{val}, -30, 70 )->pack(); $tmpbar->Label( -textvariable => \$pid{ex1}{val} )->pack(); $tmpbar->Label( -text => $pid{ex1}->{as} )->pack(); print "val Labels: $pid{ex1}->{val}\n"; dd %pid; MainLoop; sub PBar { my($frame, $val, $min, $max)=@_; print "val PBar1: $$val\n"; my $pbar=$frame->ProgressBar( -anchor=>'s', -width=>100, -length=>500, -blocks=>100, -gap=>1, -resolution=>0.5, -variable=>$val, -from=>$min, -to=>$max ); print "val PBar2: $$val\n"; dd %pid; return $pbar; }

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^2: weird case of memory corruption?
by perltux (Monk) on May 12, 2021 at 07:36 UTC
    I have never had problems with -textvariable in Labels using nested data structures despite using them frequently, this case is the first, so I think ProgressBar is somehow messing with it (you can see that ProgressBar actually resets the value of $pid{ex1}{val} to the '-from' value despite this not being a documented behaviour).

    If you try removing the ProgressBar the behaviour of the -textvariable in the Label will be consistently as expected.
      Hello again,

      you are rigth about -textvariable pointing to a nested val: it works correctly (see also why won't Tk textvariable take a reference to an array element? Tk::Entry not updating when textvariable changes. and perl/Tk Entry widget displays wrong value when -textvariable is shared).

      My dumping using Data::Dump dd method shows, if you uncomment and so use your original code PBar( $tmpbar, \$pid{ex1}->{val}, -30, 70 )->pack(); that sometimes val is undef:

      >perl tkprogressbar.pl val PBar1: -21.5 val PBar2: -30 ("ex1", { as => "temp", val => -30 }) val Labels: -30 ("ex1", { as => "temp", val => -30 }) >perl tkprogressbar.pl val PBar1: -21.5 Use of uninitialized value in concatenation (.) or string at tkprogres +sbar.pl line 39. val PBar2: ("ex1", { as => "temp", val => undef }) Use of uninitialized value in concatenation (.) or string at tkprogres +sbar.pl line 21. val Labels: ("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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found