Big Problem lazarus / 13-General ---------------------------------------------------------------------- ImbaLooser · 2012-03-07 00:02 Hey, guys i have problem. This problem is : Project project1 raised exception class 'External: SIGSEGV'. I cannt undestand its teacher 's  error or my(or Lazarus). (ex. from book) procedure DelFromList(var Start:TpoinElemList;  ForDel:integer); var wPoint:TpoinElemList; prevEl:TpoinElemList; i:integer; begin     if start = nil then Showmessage('Error!'); prevEl:=nil; Wpoint:=start; while (wpoint <> nil) and (wpoint^.name <> delcount) do     <- Lazarus show me this line after error. begin  prevel:=wpoint;  wpoint:=wpoint^.next; end; if PrevEl = nil then begin  start:=start^.next;  start^.prev:=nil;  Dispose(wpoint); end else     begin      if wpoint = nil then prevel^.next:=nil      else      begin        prevel^.next:=wpoint^.next;        wpoint^.next^.prev:=prevel;       end;       dispose(wpoint);       end; end; How fix it? [OS linux] upd. sry if i post in wrong thread ---------------------------------------------------------------------- Leledumbo · 2012-03-07 02:03 The code looks fine to me (except for the first `if` as the code would still execute the lines after it despite start is nil or not), and that line shows nil access is properly guarded. How do you call this function? ---------------------------------------------------------------------- Blaazen · 2012-03-07 10:44 I can see parameter "ForDel: integer" which seems be never used and in following line: Code: [Select]while (wpoint <> nil) and (wpoint^.name <> delcount) do     <- Lazarus show me this line after error.I don't understand why "(wpoint^.name <> delcount)" - what is name and what is delcount ? ---------------------------------------------------------------------- Martin_fr · 2012-03-07 18:06 It may be some other code dealing with that data. I would guess, that you have some "wpoint" that has a bad value for "next". That is next is not initialized (not nil) or points to a wpoint that has been freed in the meantime. then your check "wpoint <> nil" passes, but accessing "wpoint.name" will crash ---------------------------------------------------------------------- User137 · 2012-03-08 07:22 It is bad practise to just notify of error but then keep running with it. Assuming that start = nil: Code: [Select]... if start = nil then Showmessage('Error!'); prevEl:=nil; Wpoint:=start; while (wpoint <> nil) and (wpoint^.name <> delcount) do   // if start=nil, then wpoint=nil and this doesn't run ... if PrevEl = nil then // It is nil begin  start:=start^.next; // oops... ---------------------------------------------------------------------- Arbee · 2012-03-08 08:35 I had something similar in a different programming language (PL/1 to be precise) and that was because I did not use "lazy evaluation" in a construct like your: Code: [Select]while (wpoint <> nil) and (wpoint^.name <> delcount) do lazy evaluation would resolve the "while" to false as soon as wpoint is nil and then wouldn't bother anymore to check the other condition. I frankly have no idea if that is the case here.  I don't even know if FPC uses lazy evaluation or not or whether one can set it as a compiler option. ---------------------------------------------------------------------- Leledumbo · 2012-03-08 09:03 QuoteI frankly have no idea if that is the case here.  I don't even know if FPC uses lazy evaluation or not or whether one can set it as a compiler option.No, that shouldn't be the case without explicit option / directive. See remark here. ---------------------------------------------------------------------- Gizmo · 2012-03-08 11:51 What is delcount? It is not declared in vars and it is not a function.  I got this error the other day and it was because I hadn't created a StrinList that I was trying to use. the .name is part of a created stream but your wPoint structure is never created (var := wPoint.create). Maybe that is why?  I have also had it in the past in Linux when I had "Win32" specificed in the code generation options of my Project Options from previously compiling the same project on a Windows box and forgetting to revert it back to 'Default'.