So, I find this to be an interesting problem. Probably my "fix" just hides the problem, rather than fixing it. It smells of an unitialized variable "somewhere".

I have this Perl program that works consistently correctly on Win2K. On WinXP, it fails pretty regularly but not always, on certain operations.

This Perl program uses Win32::GUI, and contains a combobox widget. On occasion, and as part of the operation that makes the program fail with an access violation, it needs to read the contents of the combobox. It uses the following subroutine to do so.

After figuring out how to install symbols for Perl, using MSVC++6.0's debug IDE traceback, I discovered the failure happens in interpreting this sub, called from DoEvent. The sub is fairly straightforward, in wanting to copy each entry from the ComboBox into the key of a hash. The data are all unique, as the combobox was populated from a hash initially. The actual failure was in reading some hash value or property (if I can guess at the Perl internal symbol names reasonably).

The first subroutine below is how it was, when it worked on Win2K and failed on WinXP. The second subroutine succeeded 3 timse in a row on WinXP.

Clearly my modified version and the original version do the same job, but the modified version does it "slower" by using an intermediate array. (A slow algorithm is faster than a broken algorithm.) However, I see no reason why this should "fix" a crash, nor why the crash should be there in the first place.


# bad
#####################################
sub read_lb  # version 2002/02/23
{ my ( $lb ) = @_;
  my ( %hash, $count, $ix, $str );
  $count = $lb->Count () - 1;
  foreach $ix ( 0 .. $count )
  { $str = $lb->GetString ( $ix );
    $hash{ $str } = 1;
  }
  return \%hash;
}
#####################################


# good
#####################################
sub read_lb  # version 2002/07/26
{ my ( $lb ) = @_;
  my ( %hash, $count, $ix, @str );
  $count = $lb->Count () - 1;
  foreach $ix ( 0 .. $count )
  { push @str, $lb->GetString ( $ix );
  }
  foreach my $str ( @str )
  { $hash{ $str } = 1;
  }
  return \%hash;
}
#####################################

--
Glenn -- http://nevcal.com/
===========================
The best part about procrastination is that you are never bored,
because you have all kinds of things that you should be doing.


Reply via email to