Hey jdarling. Your PNG loader is quite useful. I incorporated your loader into my image library to load PNGs. It works nicely, but there are several problems, which at first I thought were my fault, but I made a simple test program that includes only your loader just to be sure, and it was not my fault .
Here's the test program that loads PNGs using your unit:
[pascal]
PROGRAM upngtest;
USES heaptrc, uPNGSupport;
CONST
imgFN = 'vlad.png';
VAR
p: TRawPNG = nil;
fn: string = imgFN;
BEGIN
writeln('upngtest');
writeln();
if(ParamCount > 0) then
fn := ParamStr(1);
writeln('Loading ', fn);
p := TRawPNG.Create(fn);
if(p.LoadError = 0) then begin
writeln('Loaded image: ', fn)
end else
writeln('Error: ', p.LoadError, '|', p.LoadErrorMessage);
p.Free();
writeln('Done');
END.
[/pascal]
In the above program, heaptrc will make the loader report strange errors, while without heaptrc it will load the PNGs normally.
Another thing is a range check error:
Code:
An unhandled exception occurred at $00412E5F :
ERangeError : Range check error
$00412E5F TRAWPNG__FILTERROW, line 644 of C:/Programming/FPC_PP/Projects/dIm
age/Units/uPNGSupport.pas
$004127EF TRAWPNG__DECODENONINTERLACED, line 564 of C:/Programming/FPC_PP/Pr
ojects/dImage/Units/uPNGSupport.pas
$00411AD5 TRAWPNG__READIDAT, line 345 of C:/Programming/FPC_PP/Projects/dIma
ge/Units/uPNGSupport.pas
$00414036 TRAWPNG__LOADFROMSTREAM, line 837 of C:/Programming/FPC_PP/Project
s/dImage/Units/uPNGSupport.pas
$00413AB9 TRAWPNG__CREATE, line 771 of C:/Programming/FPC_PP/Projects/dImage
/Units/uPNGSupport.pas
$0040163A main, line 20 of upngtest.pp
This range check error causes crashing when loading a certain PNG, but when the check is disabled that same PNG loads OK. The particular PNG I've used is named vlad.png from your SDL, Lua and FPC game demo which I downloaded from your site. Or for easier access I've uploaded it to imagebin.
I suspect you've got memory corruption somewhere in your code, but could be something else.
Bookmarks