Crash at first begin line of procedures, constructors etc. lazarus / 9-Editor ---------------------------------------------------------------------- LBAWinOwns · 2007-05-03 13:37 Hello! I've recently switched to Linux and thereby Lazarus. I'm not the problem is because of or partially because of Lazarus. But I don't remember ever getting similar problems with Delphi (is that word forbidden here   :oops: ?) Well, Let's say I have a normal buttonclick procedure. Let's say it is calling two procedures. "proc1" and "proc2". It calls proc1 and it goes completely fine. Most procedures or constructors don't have this problem. But when I call proc2 it crashes at it's begin line! The error is "Project raised exception class 'External: SIGSEGV'." The thing with adress and procedure are always different tough. It's interesting that it only happening to some procedures and constructors. In fact I've always been able to fix the problem by doing this: procedure proc1 (anyvariable:integer) --> procedure proc1 (const anyvariable:integer) So making the parameters constant always worked so far. But now I have a constructor that is run that has no parameter And I'm so confused . It just crashes at the begin line of the constructor. Well, thank you in advance .[/u] ---------------------------------------------------------------------- antonio · 2007-05-03 14:43 "Is that word forbidden here" I guess "market pressure" embarasses Lazarus as well. The need of being a Delphi-like IDE is putting Lazarus sick. ---------------------------------------------------------------------- eric · 2007-05-03 15:45 Can you give a simple code example? Eric ---------------------------------------------------------------------- LBAWinOwns · 2007-05-03 16:33 TGeneralRaw = class   protected     Height  : integer;     Width   : integer;     Palette : TPalette;     Data    : Ansistring;     function palettetostring: ansistring;   public     constructor create;     destructor  destroy;     procedure Sparabitmap(bmp: TBitmap);   end;                                     (Say if you wanna see all the other classes/records too) constructor TGeneralraw.create; var forer :byte; begin       // It crashes here! for forer:=0 to 255 do self.palette[forer]:=RGB.Create; end;      TPackEntry = record   Offset: DWORD;   CpSize: DWORD;   RlSize: DWORD;   Comp: WORD;   FType: Integer; {-3=hidden, -2=blank, -1=normal, >-1=repeated}   Data: string;   //heredown are added stuff for the Image Creator   modified:boolean; // Believe or not, but in fact the all works fine until i added this variable!! Now the program crashes at the constructor.   Imagetype:TImagetype;   Image:TMainpaletteraw;   replacewith:TFilename;  end;                 procedure loadpackage(plats:TFilename); var forer   :integer; lba1pal:boolean; a:byte; types:TImagetype; begin lba1pal:=true; types:=raw; opened:=true; Packentries:=Openpackfile(plats); for forer:=0 to length(Packentries)-1 do begin   Packentries[forer].Imagetype:=types;   Packentries[forer].modified:=false;   Packentries[forer].Image :=TMainPaletteRaw.create; // Note: With breakpoints I saw it crashes when the value is something like 2 or 3, not at first=0.   if lba1pal then Packentries[forer].Image.SetLba1Palette   else  Packentries[forer].Image.SetLba2Palette; end;                                               procedure TForm1.BitBtn7Click(Sender: TObject); var a:string; forer:   integer; begin   OpenDialog1.Filter:='High Quality Resource|*.HQR'; if not(OpenDialog1.Execute) then exit;   a:=OpenDialog1.FileName;   Openpackage(a); end; I extracted and cleaned out a bit of the code. Even now I guess it looks reaaaly messy for you, but I thought you see yourself what is important. The thing that it works flawless without the modified-var really shakes me! Note at the bold //comments . I've added some description how the program crashes. ---------------------------------------------------------------------- theo · 2007-05-03 16:56 I think it's not a Lazarus/FPC Problem. But we can't see in this code what happens here: Packentries:=Openpackfile(plats); What's PackEntries what does Openpackfile return? ---------------------------------------------------------------------- Wanagen · 2007-05-04 01:40 And if you rename the variable "modified"  to "mymodified" ? ---------------------------------------------------------------------- eric · 2007-05-04 06:41 Good point, 'modified' can't be used as a variable can it? Eric ---------------------------------------------------------------------- LBAWinOwns · 2007-05-04 12:29 The program uncompresses an ancient archive file format and then shows and modifies the images inside the archive. "Packentries" is containing "Packentry", it is as many "packentry" as an archive contains files. The OpenPack Function is not written by me, but the author have it working perfectly on his Delphi. Tough the reason of this error is because of that I added values to "Packentry" Function OpenPack(const data: TStream; First: Integer=-1; Last: Integer=-1): TPackEntries; var a, b, c: Integer;     Buffer: DWORD; begin  SetLength(OpOffsets,1);  with data do begin   Seek(0,soBeginning);   Read(OpOffsets[0].D,4);   OpOffsets[0].T:= -1;  //first entry is always normal   SetLength(OpOffsets,(OpOffsets[0].D div 4)-1);   for a:= 1 to Length(OpOffsets) - 1 do begin    Read(OpOffsets[a].D,4);    OpOffsets[a].T:= -1;    If OpOffsets[a].D = 0 then     OpOffsets[a].T:= -2    else     For b:= 0 to a - 1 do      If OpOffsets[a].D = OpOffsets.D then begin       OpOffsets[a].T:= b;       Break;      end;   end;   If First < 0 then First:= 0;   If Last < 0 then Last:= Length(OpOffsets) - 1   else if Last >= Length(OpOffsets) then Last:= Length(OpOffsets) - 1;   SetLength(Result,Last-First+1);   b:=0;   For a:=First to Last do begin    If OpOffsets[a].T=-1 then begin     Buffer:=OpOffsets[a].D;     repeat      If Length(Result)2) then Result.Comp:=0;      SetLength(Result.Data,Result.CpSize);      Read(Result.Data[1],Result.CpSize);      Inc(Buffer,Result.CpSize+10);      Inc(b);      c:=FindNextOffset(a);     until Buffer>=OpOffsets[c].D;    end    else begin     If Length(Result)-1 then begin      Result.Offset:=OpOffsets[a].D;      Result.CpSize:=Result[OpOffsets[a].T].CpSize;      Result.RlSize:=Result[OpOffsets[a].T].RlSize;      Result.Comp:=Result[OpOffsets[a].T].Comp;      Result.Data:=Result[OpOffsets[a].T].Data;     end     else begin      Result.CpSize:=0;      Result.RlSize:=0;     end;     Result.FType:=OpOffsets[a].T;     Inc(b);    end;   end;  end;  SetLength(Result,b);  SetLength(OpOffsets,0); end; Function OpenPackFile(path: String; First: Integer=-1; Last: Integer=-1): TPackEntries; var FStr: TFileStream; begin  FStr:=TFileStream.Create(path,fmOpenRead);  Result:=OpenPack(FStr,First,Last);  FStr.Free; end; By the way, I must confess that I installed Lazarus in a very strange way. I didn't understand which file to download and install, so I installed all add ons to Lazarus except Win32-package (because it failed), then I realized that the zip I downloaded contained everything but lazarus... Might that be the cause of it? Oh, and editing the name of modified ain't fixing it neither . Thanks a lot for helping anyway ---------------------------------------------------------------------- LBAWinOwns · 2007-05-24 19:07 hmmm, I solved it. The thing is, I really overused OOP when I had no reason at all to do use it. I just made my RGB class to a normal record. Much better this way. However I still think Delphi would make it working flawlessly, oh well. Lazarus is great too! ---------------------------------------------------------------------- Almindor · 2007-05-26 21:47 The symptoms you described are similar to a memory corruption. Compile your code with "-Criot -ghl" and see the result. I bet it'll crash with a long list of errors. Delphi probably worked because it had slightly different memory layout (but the bug was there too).