Hello. I am using BGRABitmap in my project to draw some graphical scene. As there is obvious need to show it, when everything is done, I draw the content of BGRABitmap image on TImage canvas. Also, there is a requirement to show initial scene right after application start, so I am just using OnCreate event of the main form (an instance of TImage is added at design time, so exists before entering FormCreate). Theoretically it should work just fine. But in fact, after second attempt to draw content of BGRABitmap to TImage canvas 'External: SIGSEGV' error occurs (this happens on event (say button clicked) after Application.Run was invoked). The error doesn't happen when I do not draw the initial scene in FormCreate, however such code looks ideologically valid to me.
I've created sample project to reproduce the issue (see attachment). Here is the essential code:
procedure TForm1.Button1Click(Sender: TObject);
var
bgra : TBGRABitmap;
aCanvas : TCanvas;
begin
bgra := TBGRABitmap.Create(Image1.Width, Image1.Height);
try
aCanvas := bgra.Canvas;
aCanvas.TextOut(10, 10, 'Test');
aCanvas.TextOut(100, 100, '2222');
bgra.Draw(Image1.Canvas, 0, 0, True);
finally
bgra.Free();
end;
//begin
// Image1.Canvas.TextOut(10, 10, 'Test');
// Image1.Canvas.TextOut(100, 100, '2222');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1Click(Sender);
end;
So, when run the application, the text will appear in the image, but when click the button - 'External: SIGSEGV' error happens. However, the error doesn't happen if canvas of TImage is used directly (see commented code) OR we do not attempt to draw in FromCreate (comment Button1Click invocation in FormCreate and then, when click the button two or more times - everything is ok).
Is it a bug, or I just miss something?
Environment:
Linux Mint 20.3 (Una)
Lazarus 2.0.6+dfsg-3, FPC 3.0.4, linux gtk2 (from standard repository, a bit older, I know)