Crash problem in 32bit but not in 64bit lazarus / 62-General ---------------------------------------------------------------------- Tommi · 2018-07-11 12:27 This is my code attempts to convert a byte array to single: Code: [Select]function bytes2float(var dd:TMioR;tipo:byte;Precision:byte;aa:Tbytes;Posiz:integer):single; overload;     //Prcision in byte non in bit var   oo:array [0..3] of byte; begin   try     if tipo = 0 then     begin       if aa[posiz]<128 then       begin            if Precision = 1 then result:=aa[posiz];            if Precision = 2 then result:=aa[posiz]*256+aa[posiz+1];       end       else       begin            if Precision = 1 then result:=-(255-aa[posiz]+1);            if Precision = 2 then result:=-(65535-(aa[posiz]*256+aa[posiz+1])+1);       end;     end;     if tipo = 1 then     begin       oo[3]:=aa[Posiz];       oo[2]:=aa[Posiz+1];       oo[1]:=aa[Posiz+2];       oo[0]:=aa[Posiz+3];       move(oo,result,4);       if IsNAN(result) then result:=0;     end;   Except   on E : Exception do   begin      result:=0;      setlength(dd.Errori,length(dd.Errori)+1);      dd.Errori[Length(dd.Errori)-1].Testo:='Trovato errore generico.';      dd.Errori[Length(dd.Errori)-1].Codice:=8;   end;   end; end; When tipo=1, sometime in 32bit this code crashes. In 64 works. Some idea ? Thank you ---------------------------------------------------------------------- Gammatester · 2018-07-11 12:49 Quote from: Tommi on July 11, 2018, 02:27:44 pmCode: [Select]      begin            if Precision = 1 then result:=-(255-aa[posiz]+1);            if Precision = 2 then result:=-(65535-(aa[posiz]*256+aa[posiz+1])+1);       end;     end; Are you sure that  Code: [Select]if Precision = 1 then result:=-(255-aa[posiz]+1) is correct and not Code: [Select]if Precision = 1 then result:=-(255-aa[posiz+1])At all other places the $+1$ is in the index expression. ---------------------------------------------------------------------- Tommi · 2018-07-11 12:50 It isn't there the prblem because it happens when tipo = 1 so when I am here: Code: [Select]    if tipo = 1 then     begin       oo[3]:=aa[Posiz];       oo[2]:=aa[Posiz+1];       oo[1]:=aa[Posiz+2];       oo[0]:=aa[Posiz+3];       move(oo,result,4);       if IsNAN(result) then result:=0;     end; ---------------------------------------------------------------------- Gammatester · 2018-07-11 13:00 Sorry, you are right. I was confused by the indentation. ---------------------------------------------------------------------- Tommi · 2018-07-11 13:02 specifically the problem borns when : oo[0]=0 oo[1]=0 oo[2]=0 oo[1]=63 if I put result:=0.5 in the line above if IsNAN(result) then result:=0;  the crash disappears. ---------------------------------------------------------------------- Tommi · 2018-07-11 13:24 The error is indipendent from the content of the function because if I just put result:=0; in the first row of the function, the application crashes there. ---------------------------------------------------------------------- Tommi · 2018-07-11 16:11 Issue solved creating a new project and copying the units. 32bit version of lazarus cannot open 64bit created projects because it gives this random errors. ---------------------------------------------------------------------- Thaddy · 2018-07-11 17:10 Quote from: Tommi on July 11, 2018, 06:11:56 pmIssue solved creating a new project and copying the units. 32bit version of lazarus cannot open 64bit created projects because it gives this random errors. That would be a bug. ---------------------------------------------------------------------- Tommi · 2018-07-11 21:17 In few words: my code was working good compiled with 64bit version of lazarus. I opened the same project with 32bit and I had this problem. I reopened the same files (already modified with 32 bit version) with 64bit, and I had a lot of issues. GDB crashing and exe project remaining in memory with no hope to close it from taskmanager, reboot was necessary. I created a new project copying the units and everything started to work fine. So I tried also to copy lpi, lpr, lps, res files coming from an old 64 bit version (not touched from the 32) in the ruined project and it came back to work fine (compiling with 64bit). Yes, I am pretty sure that it is a bug, but it is very difficult to create a minimal project to reproduce it.