in reply to Re^2: perl tk script dumps core?!
in thread perl tk script dumps core?!

These lines of code cause the segfault and core dump:

my $button1 = $mw->Photo(-data => &encoded_but1, -format => 'gif'); my $button2 = $mw->Photo(-data => &encoded_but2, -format => 'gif'); my $button3 = $mw->Photo(-data => &encoded_but_exit1, -format => 'gif' +); my $button4 = $mw->Photo(-data => &encoded_but_exit2, -format => 'gif' +); my $but1 = $c->createImage(40, 400, -image => $button1, -anchor => 'nw +', -tags => ['but1']); $c->bind( $but1, '<Enter>', sub {$c->itemconfigure( $but1, -image => $ +button2); }); $c->bind( $but1, '<Leave>', sub {$c->itemconfigure( $but1, -image => $ +button1); }); $c->bind( $but1, '<ButtonPress>', sub{ &tabbed; } ); my $but2 = $c->createImage(450, 400, -image => $button3, -anchor => 'n +w', -tags => ['but2']); $c->bind( $but2, '<Enter>', sub {$c->itemconfigure( $but2, -image => $ +button4); }); $c->bind( $but2, '<Leave>', sub {$c->itemconfigure( $but2, -image => $ +button3); }); $c->bind( $but2, '<ButtonPress>', sub { &disconnect; $mw->fontDelete('info_rus'); $mw->fontDelete('ticks'); $mw->fo +ntDelete('bar_rus'); $mw->fontDelete('dial_rus'); exit; });

Replies are listed 'Best First'.
Re^4: perl tk script dumps core?!
by Anonymous Monk on Jul 08, 2011 at 09:29 UTC
Re^4: perl tk script dumps core?!
by Anonymous Monk on Jul 08, 2011 at 11:00 UTC
    I noticed that the error occurs after activating the Quit button (выход), but not if the application is closed from the frame's close button on the title bar.

      I noticed that the error occurs after activating the Quit button (выход), but not if the application is closed from the frame's close button on the title bar.

      Try calling destroy on your mainwindow instead of perl function exit, or maybe use Tk::exit

        Today I found that Device::SerialPort was causing the core dump. The "exit" command called by a button did not entirely end the serial communication going on and that caused the core dump. I added some lines of code so that the button only chaned a variable and based on that variable a "disconnect" and "exit" command was issued from within the main subroutine -- the dumping of core stopped! Many thanks to all for the suggestions and help!!!