#46 Crash on Exit when using Win32-GUI objects in circular link


Running the code below will cause a crash on 5.8.7/5.6
with Win32-GUI 1.02 when the programme is exited.

use strict;
use Win32::GUI;

#We init the EmployeeSelector class

# Create the main window
my $mainwindow = new Win32::GUI::Window(
-name => "Window",
-title => "Objects and Windows",
-pos => [100,100],
-size => [400,400],

#We now create several employee selector 'controls'.
my $search1=EmployeeSelector->new
my $search2=EmployeeSelector->new
my $search3=EmployeeSelector->new
my $search4=EmployeeSelector->new
my $search5=EmployeeSelector->new
#Show all our controls

#Enter the message processing loop

package EmployeeSelector;
#Class spefic globals
my $searchwindow; #The search window
my $active; #The active object

sub Init {
#This is a class function, and is used to initilise all
$searchwindow = new Win32::GUI::DialogBox(
-name => "EmployeeSelector",
-title => "Search for Employee",
-size => [300,270],
-name => 'ListView',
-pos => [8,8],
-size => [280,189],
-fullrowselect=> 1,
$searchwindow->AddButton (
-name => 'OK',
-text => 'OK',
-pos => [164,208],
-size => [60,21],
#When we click ok, we populate the calling controls
-onClick => sub {my $item=$searchwindow-
my %hItem=$searchwindow->ListView-
return -1;
$searchwindow->AddButton (
-name => 'Cancel',
-text => 'Cancel',
-pos => [228,208],
-size => [60,21],
-onClick => sub {return -1},
#populate the list view
$searchwindow->ListView->InsertColumn(-width =>
55,-text => 'Emp ID');
$searchwindow->ListView->InsertColumn(-width =>
205,-text => 'Employee Name');
$searchwindow->ListView->InsertItem(-text =>
[1234, 'Bob Smith']);
$searchwindow->ListView->InsertItem(-text =>
[4321, 'Peter Jones']);
$searchwindow->ListView->InsertItem(-text =>
[7890, 'John Brown']);

#The constructor
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
bless ($self, $class);
my ($parent,$xcor,$ycor)=@_;
#Create window
my $childwin = new Win32::GUI::Window (
-parent => $parent,
-name => "ChildWin",
-pos => [$xcor,$ycor],
-size => [150, 24],
-popstyle => Win32::GUI::WS_CAPTION |
-pushstyle => Win32::GUI::WS_CHILD |
#add the window to the object
#Create other controls
-name => 'Label',
-text => 'ID#',
-height => 20,
-width => 20,
-top => 6,
-left => 0,
$childwin->AddTextfield (
-name => 'EmpID',
-height => 20,
-width => 35,
-top => 2,
-left => 20,
-tip => 'Employee ID',
$childwin->AddButton (
-name => 'Search',
-text => 'Search',
-height => 20,
-width => 60,
-top => 2,
-left => 60,
-tip => 'Search for a Employee ID',
#$self will become a closure
-onClick => sub {Search($self)},
return $self;

sub Search {
#Open the search window - can be called as a method
or as an event handler
my $self=shift;
#Set the active object to be this object

sub SetEmpID {
#Set the EmpID of the text box - can be called as a
method or as an event handler
my $self=shift;

sub Show {
#Show the window
my $self=shift;

sub Hide {
#Hide the window
my $self=shift;

sub Move {
#Move the window
my $self=shift;

#We have a circular link(?)
my $self=shift;
print 'in Destroy'.$self;


  • Nobody/Anonymous

    Logged In: NO

    Still a problem under 1.03

  • Robert May

    Robert May - 2005-12-02
    • assigned_to: nobody --> robertemay
  • Robert May

    Robert May - 2005-12-02

    Logged In: YES


    I think this is the example that you posted to the users
    list for feedback from others earlier in the year. The
    example in this tracker does not crash for me (Win32::GUI
    1.03, Win98, Perl 5.8.7). Can you let me know if it is
    still a problem for you? If so, can you let me have details
    of error messages, OS, perl and Win32::GUI versions.


  • Nobody/Anonymous

    Logged In: NO


    Still a problem for me...

    Looks like this is going to be a real pain to track down.
    I've now upgraded to perl 5.8.7 for all development, so my
    environment is:

    Win32::GUI 1.03, WinXP (sp2), Perl 5.8.7

    I've tested this with both the ppm from sourceforge and
    manually built Win32::GUI (mingw). When running under a
    mingw version, I get the following trace:

    perl.exe caused an Access Violation at location 280899be
    in module perl58.dll Reading from location fffffffb.

    eax=ffffffff ebx=0023418c ecx=00232770 edx=00232784
    esi=fffffff3 edi=00232770
    eip=280899be esp=0140f99c ebp=0140f9f8 iopl=0 nv
    up ei ng nz na po nc
    cs=001b ss=0023 ds=0023 es=0023 fs=003b
    gs=0000 efl=00000286

    Call stack:
    280899BE perl58.dll:280899BE Perl_my_socketpair
    233C7932 GUI.dll:233C7932 ControlMsgLoop(HWND__*,
    unsigned, unsigned, long) GUI_MessageLoops.cpp:824
    LRESULT ControlMsgLoop(HWND__*, unsigned, unsigned, long)(
    HWND hwnd = &(indirect),
    UINT uMsg = 2,
    WPARAM wParam = 0,
    LPARAM lParam = 0
    PerlResult = DefWindowProc(hwnd, uMsg,
    wParam, lParam);
    return PerlResult;
    case WM_TIMER:

  • Robert May

    Robert May - 2005-12-02

    Logged In: YES


    Although I can't reproduce this, the stack trace point to
    the same issue that I think I've resolved looking at
    Tracker 1243378 (Richedit crash on exit). Once I've
    checked in my latest changes (probably tomorrow) I'd
    appreciate it if you could test and see if that fixes this


  • Robert May

    Robert May - 2005-12-03
    • priority: 5 --> 1
    • status: open --> open-fixed
  • Robert May

    Robert May - 2005-12-03

    Logged In: YES

    Based on our email conversation I'm going to mark this as
    fixed. The fix in is CVS, and will make it into the v1.04

  • Robert May

    Robert May - 2006-10-15
    • status: open-fixed --> closed-fixed

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks