Hi, I just noticed when loading jpeg from a non-ui thread (task) causes it to decoded to black image randomly.
Following code demonstrate the issue. This issue mostly occur when I move the mouse on the main window.
Just found out that the bug occur within the Img32.Fmt.JPG.pas -> LoadFromStream method.
In the following line, Canvas.Handle occasionally becomes zero when called from background thread.
Hi, I just noticed when loading jpeg from a non-ui thread (task) causes it to decoded to black image randomly.
Following code demonstrate the issue. This issue mostly occur when I move the mouse on the main window.
Just found out that the bug occur within the Img32.Fmt.JPG.pas -> LoadFromStream method.
In the following line, Canvas.Handle occasionally becomes zero when called from background thread.
Then I realized the issue comes from the TJpegImage class. TJpegImage.Canvas.Handle occasionally becomes zero when called from a background thread.
After searching more on the subject, I found following two links:
https://en.delphipraxis.net/topic/1292-why-is-this-code-not-thread-safe-delphi-7/?do=findComment&comment=10765
http://www.delphigroups.info/1/6/28001.html
According to those links, we need to wrap the CopyFromDC within the Canvas.Lock and Canvas.Unlock methods.
Here is my fix for TImageFormat_JPG.LoadFromStream method:
Thank you for the very helpful feedback. I'll make the changes you suggested. Cheers.