Crash during runtime on TBitmap.CreateIntfImage; on specific files
Original Reporter info from Mantis: misheque
-
Reporter name: Kris
Original Reporter info from Mantis: misheque
- Reporter name: Kris
Description:
When calling TBitmap.CreateIntfImage on specific files, during runtime the program crashes (and during debugging, the IDE freezes)
Steps to reproduce:
Only reproducible on specific files, thus included is file password_field16.png that crashes the program every time. In my scenario, there is a loop running procedure on every file from the list, and only very specific files crashes the program.
IMPORTANT: This code is executed from within Thread.
code:
const
C_4K = 1080*720*4;
var
Pic : TImage;
t : TLazIntfImage;
res : int64;
begin
AData := nil;
t := nil;
Pic := TImage.Create(nil);
try
try
Pic.Picture.Bitmap.PixelFormat := pf32bit;
Pic.Picture.LoadFromFile(AFilename);
Res := Pic.Picture.Bitmap.Width*Pic.Picture.Bitmap.Height;
if(Res<1)or(res>C_4K)then exit;
//...
//(AData as TBitmap).LoadFromIntfImage(t);
fpSystem('echo "'+AFileName+'\n" >> log.txt');
t := Pic.Picture.Bitmap.CreateIntfImage;
FreeAndNil(t);
except
on E: Exception do exit;
end;
finally
FreeAndNil(t);
FreeAndNil(Pic);
end;
Additional information:
I verified that this error does not occur when the very same code is executed from outside of the Thread. It makes me think it has something to do with acquiring handles to TCanvas or HBitmap or sth alike.
Very interestingly, it does not matter for most of the other PNG files in my folder, but only crashes on specific ones, and always on the same ones.
I think this problem might be somehow related to the reason for which I needed to use TLazIntfImage in the first place, which is that I want to load thumbnails in a Thread, yet I cannot call TCanvas.CopyRect method from within the thread (unless through Synchronize() off course), because is internally does some checking on TCanvas.Handle property, and it somehow is non-thread-safe. Turns out TBimap.CreateIntfImage is also non-thread-safe, but only selectively, on some specific files, but not on others (I double checked this, even by only having 1 file on my list of files to process).
It seems, that in Lazarus, apart from loading graphic file into a TPicture, nothing else can be done on it inside a Thread without Synchronize, and it seems to me it has to do with TCanvas.Handle property and some checks on it.
Resizing large images to small thumbnails is time consuming process, so I wanted to handle that inside a thread, but now I cannot make the resizing in it unless via Synchronize() which does not work toward smooth loading.
Mantis conversion info:
- Mantis ID: 28992
- OS: Linux
- OS Build: Ubuntu 14.04 LTS
- Platform: x86_64
- Version: 1.4.2