For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > November 2004 > $MainWindow->destroy() causes hash error









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author $MainWindow->destroy() causes hash error
D. Marxsen

2004-11-25, 8:59 am

Hello *,

I used $wi_main->destroy() in many scripts to close a Tk application. But in
the script I just prepare I get a strange behaviour:

--- CUT start (heavily boilt down) ---

$wi_main=MainWindow->new;
&buildmainwin;

MainLoop;

sub buildmainwin
{
# some stuff which makes up the window ... then:
$wi_main->repeat(1000,\&cyclictasks);
}

sub cyclictasks
{
# Some condition calculations etc. ...
if($condition==1)
{
$wi_main->destroy();
}
}

--- CUT end ---

Misbehaviour:
As soon as the cyclictasks routine calls destroy, the program terminates
with an error:

1cc5540 is not a hash at c:/tools/perl/site/lib/Tk.pm line 340.

When I close the window manually, I get no error.
Yes, I tried to increase the delay time to be sure that it doesn't overtake
itself - no cure.
What is wrong?


perl -v :

This is perl, v5.8.0 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2002, Larry Wall

Binary build 805 provided by ActiveState Corp. http://www.ActiveState.com
Built 18:08:02 Feb 4 2003


Cheers,
Detlef.

--
D. Marxsen, TD&DS GmbH
detlef.marxsen@tdds-gmbz.de (replace z with h, spam protection)


D. Marxsen

2004-11-25, 8:59 am

Sorry, forgot to tell that I rebuild the main window in-between.
I kill all of its content ...

--- CUT start ---

@kids=$wi_main->children();
foreach $kid (@kids)
{
$kid->destroy() if Tk::Exists($kid);
}

--- CUT end ---

.... and then fill in some new widgets.
After this process, the destroy produces the error. Before, it works fine.
Does the kill influence the $wi_main itself?

Cheers,
Detlef.

--
D. Marxsen, TD&DS GmbH
detlef.marxsen@tdds-gmbz.de (replace z with h, spam protection)


zentara

2004-11-25, 3:56 pm

On Thu, 25 Nov 2004 10:47:54 +0100, "D. Marxsen"
<detlef.marxsen@tdds-gmbz.de (replace z with h, spam protection)> wrote:

>I used $wi_main->destroy() in many scripts to close a Tk application. But in
>the script I just prepare I get a strange behaviour:
>
>--- CUT start (heavily boilt down) ---
>
>$wi_main=MainWindow->new;
>&buildmainwin;
>
>MainLoop;
>
>sub buildmainwin
>{
> # some stuff which makes up the window ... then:
> $wi_main->repeat(1000,\&cyclictasks);
>}
>
>sub cyclictasks
>{
> # Some condition calculations etc. ...
> if($condition==1)
> {
> $wi_main->destroy();
> }
>}
>
>--- CUT end ---
>
>Misbehaviour:
>As soon as the cyclictasks routine calls destroy, the program terminates
>with an error:
>
>1cc5540 is not a hash at c:/tools/perl/site/lib/Tk.pm line 340.
>
>When I close the window manually, I get no error.
>Yes, I tried to increase the delay time to be sure that it doesn't overtake
>itself - no cure.
>What is wrong?


I'm not sure what your problem is, but I have seen similar errors and I
needed to cancel the timer before destroying the window.

Maybe:

my $repeater = $wi_main->repeat(1000,\&cyclictasks);

sub cyclictasks
{
# Some condition calculations etc. ...
if($condition==1)
{
$repeater->cancel;
$wi_main->destroy();
}
}



--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
D. Marxsen

2004-11-26, 9:02 am

"zentara" <zentara@highstream.net> schrieb im Newsbeitrag
news:nsubq01698e0ikd0or6hoairueg40pcpvh@
4ax.com...
> On Thu, 25 Nov 2004 10:47:54 +0100, "D. Marxsen"
> <detlef.marxsen@tdds-gmbz.de (replace z with h, spam protection)> wrote:
>

....
[color=darkred]
> I'm not sure what your problem is, but I have seen similar errors and I
> needed to cancel the timer before destroying the window.
>
> Maybe:
>
> my $repeater = $wi_main->repeat(1000,\&cyclictasks);
>
> sub cyclictasks
> {
> # Some condition calculations etc. ...
> if($condition==1)
> {
> $repeater->cancel;
> $wi_main->destroy();
> }
> }


Hi ...
.... I tried that, but, alas, it doesn't remove the error.
I even tried to cancel the repeater before reconstructing the window and
installing it again afterwards: No cure.
I changed "$wi_main->destroy();" to "exit;" now, to circumvent the problem.
I lost the possibility to do anything after the MainLoop but that's not
important in this case.

Anyway, thanks for your suggestions!

Detlef

--
D. Marxsen, TD&DS GmbH
detlef.marxsen@tdds-gmbz.de (replace z with h, spam protection)


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com