<philosophical question>
Is this the appropriate forum for the following question, or should I direct
these to perl-xs?  This mailing list is so much snappier, it's hard to
resist.  And the code below _was_ Inline'd after all.
</philosophical question>

I have a Perl::Tk program which calls a module I have written, containing
some Inline'd wrappers to the libtiff library.

All works fine under Linux.  Now I am trying to port in to Win32.  Things go
pretty well, until the _second_ time I call a function containing the
following code (it seems that this is the offending bit, based on some
debugging I've been doing).  The second time I call the xsub containing this
code, the program bombs with "Perl.exe has generated errors and will be
closed by Windows...an error log will be created".  (One problem is I can't
find the resulting log).  Because of the fact that it works the first time,
I am led to believe I am mismanaging the reference counts or something along
those lines and that Perl is dying during garbage collection.  I have tried
every possible permutation I could think of as far as incrementing or
mortalizing variables.  Note that r, g, and b are mortalized SV*'s (but not
s, since I return the value pointed to).  Can someone spot the error? (BTW,
I know I should be checking the return value of av_fetch before
dereferencing...but again, it works under Linux).

Here's the snippet:

  printf("Ok\n"); // I get here the second time around
  for(y = 0; y < h; y++)
  {
    strcpy(pixels, "");
    for (x = 0; x < w; x++)
    {
      r = *av_fetch(avImage, ((y * w) + x) * 3, 0); 
      g = *av_fetch(avImage, ((y * w) + x) * 3 + 1, 0); 
      b = *av_fetch(avImage, ((y * w) + x) * 3 + 2, 0); 
      sprintf(pixel, "#%02X%02X%02X ", SvIV(r), SvIV(g), SvIV(b));
      strcat(pixels, pixel);
    }
    s = newSVpv(pixels, 0);
    av_push(avCanvas, s);
  }    
  free(pixel);
  free(pixels);
  printf("Ok\n"); // but not here.
  return newRV_noinc((SV*)(avCanvas));
}

Thanks,
Eric

Reply via email to