* * *

Author Topic: Crash problem in 32bit but not in 64bit  (Read 345 times)

Tommi

  • Full Member
  • ***
  • Posts: 179
Crash problem in 32bit but not in 64bit
« on: July 11, 2018, 02:27:44 pm »
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

  • New member
  • *
  • Posts: 49
Re: Crash problem in 32bit but not in 64bit
« Reply #1 on: July 11, 2018, 02:49:17 pm »
Code: [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

  • Full Member
  • ***
  • Posts: 179
Re: Crash problem in 32bit but not in 64bit
« Reply #2 on: July 11, 2018, 02:50:41 pm »
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

  • New member
  • *
  • Posts: 49
Re: Crash problem in 32bit but not in 64bit
« Reply #3 on: July 11, 2018, 03:00:30 pm »
Sorry, you are right. I was confused by the indentation.
« Last Edit: July 11, 2018, 03:02:28 pm by Gammatester »

Tommi

  • Full Member
  • ***
  • Posts: 179
Re: Crash problem in 32bit but not in 64bit
« Reply #4 on: July 11, 2018, 03:02:45 pm »
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

  • Full Member
  • ***
  • Posts: 179
Re: Crash problem in 32bit but not in 64bit
« Reply #5 on: July 11, 2018, 03:24:26 pm »
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

  • Full Member
  • ***
  • Posts: 179
Re: Crash problem in 32bit but not in 64bit
« Reply #6 on: July 11, 2018, 06:11:56 pm »
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

  • Hero Member
  • *****
  • Posts: 6362
Re: Crash problem in 32bit but not in 64bit
« Reply #7 on: July 11, 2018, 07:10:15 pm »
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.
That would be a bug.
I am enjoining wine, not whine....

Tommi

  • Full Member
  • ***
  • Posts: 179
Re: Crash problem in 32bit but not in 64bit
« Reply #8 on: July 11, 2018, 11:17:05 pm »
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.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus