Raise exception in a CreateIntFImage lazarus / 39-Graphics ---------------------------------------------------------------------- BlueIcaro · 2012-08-18 15:10 Hello, I trying to load a PNG file, as make the example, that come with Lazarus, OpenGlControlDemo. So I copy the function LoadflTextImage2DfromPNG, and for Test I wrote this small program. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes  { you can add units after this },  Graphics, IntfGraphics,Gl,Fpimage;  TYpe   { TglTexture }  TglTexture= class    public      width ,Height : Longint;      Data          : Pointer;      destructor Destroy;Override;   end; var  P: TPortableNetworkGraphic;  InfImage: TLazIntfImage;  Textura : TglTexture;  Pb: PByte;  X,Y: Integer;  c : TFpColor;{ TglTexture } destructor TglTexture.Destroy;begin  Data := Nil;  //Data.Free;  inherited Destroy;end; begin  Textura := TglTexture.Create;  InfImage := nil;   P := TPortableNetworkGraphic.Create;  P.LoadFromFile('Texture1.png');  InfImage := P.CreateIntfImage;  Textura.width:= P.Width;   Textura.Height:=P.Height;  Getmem(Textura.Data,Textura.width * Textura.Height * 3);  Pb := PByte (Textura.Data);   For Y := 0 To P.Height-1 do  Begin    For X := 0 To P.Width do    Begin      c:=InfImage.Colors[x,y];      Pb^:= c.red shr 8;      inc(pb);      Pb^:=c.Green shr 8;      inc(pb);      Pb^:=c.blue shr 8;      inc(pb);    end;  end;  ReadLn;  P.Free;  InfImage.Free;  Textura.Free;end.     But in the line Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i InfImage := P.CreateIntfImage; I got a exception of the debugger: Extenal SigSev. But If I run the example that come with Lazarus, every thing goes ok. I don't know what I doing wrong. Any idea? Thank /BlueIcaro ---------------------------------------------------------------------- Blaazen · 2012-08-18 15:26 This is starnge. I didn't see the demo, but here: Code: [Select]  P: TPortableNetworkGraphic;   InfImage: TLazIntfImage; are two different types and you create like this: Code: [Select]InfImage := P.CreateIntfImage; ---------------------------------------------------------------------- BlueIcaro · 2012-08-18 16:59 Yes Blaazen, it's very strange, but I copy and paste de original function, and I got the same problema. Also I add the same requiered packaged  . But it's doesn't work. /BLueIcaro ---------------------------------------------------------------------- Blaazen · 2012-08-18 20:24 Sorry, my mistake. "InfImage := P.CreateIntfImage;" is not a constructor. I can see that original code is in try..except construction. You should do it too. Code: [Select]function LoadglTexImage2DFromPNG(PNGFilename: string; Image: TglTexture   ): boolean; var   png: TPortableNetworkGraphic;   IntfImg: TLazIntfImage;   y: Integer;   x: Integer;   c: TFPColor;   p: PByte; begin   Result:=false;   png:=TPortableNetworkGraphic.Create;   IntfImg:=nil;   try     png.LoadFromFile(PNGFilename);     IntfImg:=png.CreateIntfImage;     Image.Width:=IntfImg.Width;     Image.Height:=IntfImg.Height;     GetMem(Image.Data,Image.Width*Image.Height * 3);     p:=PByte(Image.Data);     for y:=0 to IntfImg.Height-1 do begin       for x:=0 to IntfImg.Width-1 do begin         c:=IntfImg.Colors[x,y];         p^:=c.red shr 8;         inc(p);         p^:=c.green shr 8;         inc(p);         p^:=c.blue shr 8;         inc(p);       end;     end;   finally     png.Free;     IntfImg.Free;   end;   Result:=true; end;              Unfortunally, this demo does not work here on my laptop. ---------------------------------------------------------------------- BlueIcaro · 2012-08-18 21:27 Hi Blaazen, I copied the function and it doesn't work. But I found something interesting. I was making my test in a Program. I selected a Program from  Proyect/New Proyect, the Program and it's doesn't work. But If I make a application, it's works find. I don't know why, but this code works Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,  IntfGraphics,Gl,FPimage; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  private    { private declarations }  public    { public declarations }  end;TYpe { TglTexture } TglTexture= class  public    width ,Height : Longint;    Data          : Pointer;    destructor Destroy;Override; end; varP: TPortableNetworkGraphic;InfImage: TLazIntfImage;Textura : TglTexture;Pb: PByte;X,Y: Integer;c : TFpColor; var  Form1: TForm1; implementation{ TglTexture } destructor TglTexture.Destroy;beginData := Nil;//Data.Free;inherited Destroy;end;{$R *.lfm} { TForm1 }function LoadglTexImage2DFromPNG(PNGFilename: string; Image: TglTexture  ): boolean;var  png: TPortableNetworkGraphic;  IntfImg: TLazIntfImage;  y: Integer;  x: Integer;  c: TFPColor;  p: PByte;  Cadena: String;begin  Result:=false;  png:=TPortableNetworkGraphic.Create;  IntfImg:=nil;  Cadena := ExpandFileNameUTF8(PNGFilename);  try    png.LoadFromFile(ExpandFileNameUTf8 (PNGFilename));    IntfImg:=png.CreateIntfImage;    Image.Width:=IntfImg.Width;    Image.Height:=IntfImg.Height;    GetMem(Image.Data,Image.Width*Image.Height * 3);    p:=PByte(Image.Data);    for y:=0 to IntfImg.Height-1 do begin      for x:=0 to IntfImg.Width-1 do begin        c:=IntfImg.Colors[x,y];      p^:=c.red shr 8;        inc(p);        p^:=c.green shr 8;        inc(p);        p^:=c.blue shr 8;        inc(p);      end;    end;  finally    png.Free;    IntfImg.Free;  end;  Result:=true;end; procedure TForm1.Button1Click(Sender: TObject);var  Tex: TglTexture;begin  Tex := TglTexture.Create;  IF LoadglTexImage2DFromPNG('Texture1.png',Tex) Then     ShowMessage('si')  ELSE    ShowMessage ('No');  IF Tex <> nil Then   ShowMessage('No nil')  ELSE      ShowMessage('Nil');end; end.                                                                            I think there is some importan diference between a Application and a Program. /BlueIcaro ---------------------------------------------------------------------- BlueIcaro · 2012-08-18 21:35 I don't know why, but if this code doesn't run into a GUI Application (Application with forms) it doesn't work  /BlueIcaro