I encountered an odd issue: when I have the memory leak report option enabled, the following code triggers an exception with "Invalid floating point operation", but only the 1st time it is used. If I call it again there is no exception and the call succeeds. When closing the app there is this report about a leak:
the test code:
Code: Select all
function FastJpegFileToBitmap(fle: string): Graphics.TBitmap;
Var PJ: PJpegDecode;
j: TJpegImage;
m: TMemoryStream;
err: TJpegDecodeError;
begin
Result := nil;
m := TMemoryStream.Create;
With m do begin
Try
LoadFromFile(fle);
Except
m.Free;
Exit;
End;
try
Err := jpegdec.JpegDecode(Memory,Size,PJ);
except
On E:Exception
do ShowMessage(e.Message);
end;
if Err <> JPEG_SUCCESS then begin
ShowMessage('pic error');
showmessage(jpegdec.JpegErrorToStream(Err));
//
m.Free;
PJ^.Free;
// use default
j := TJPEGImage.Create;
j.Performance := jpBestSpeed;
try
Result := Graphics.TBitmap.Create;
j.LoadFromFile(fle);
With Result do begin
Height := j.Height;
Width := j.Width;
Assign(j);
end;
except
FreeAndNil(Result);
FreeAndNil(j);
Exit;
end;
FreeAndNil(j);
Exit;
end;
showmessage('success');
// SSE Jpeg success
Result := PJ^.ToBitmap;
PJ^.Free;
end;
m.Free;
end;
Is this an issue with madExcept or something related to the jpegdec unit?
I tested without madExcept, using only ReportMemoryLeaksOn.. and also with FastMM4 fulldebug mode, it worked fine in those cases, no exception and no memory leak reported.