I run a local programming mixed ability group. I use Linux Mint 19.1 and they use Windows 7, 8, 10.
We are looking at the basics of sprites, using the LCL. (I know we should use BGRABitmap, but some of the group have never coded before, and they already have many new concepts to deal with.)
In Linux Mint 19.1 Cinnamon with GTK2 everything works correctly.
In Windows the sprites leave trails and heaptrace shows a memory leak.
I have tested with fpc 3.04 and both Laz 1.8 fixes and Laz 2.0 fixes in Linux and 1.8 fixes in Windows
The problems seem to occur at the imgBuffer.Assign(imgBackGround) statement in the following code. It seems that the assignment of the standard background to the buffer does not work properly when the procedure is triggered by a timer.
procedure TForm1.MoveSprite;
beginIn Linux Mint 19.1 everything works correctly.
// Movement of sprite by keyboard: UP/DOWN/LEFT/RIGHT arrows advance smooth version
if (GetKeyState(VK_LEFT) < 0) then
if (iSpLeft >= 10) then
iSpLeft := iSpLeft - 10;
if (GetKeyState(VK_RIGHT) < 0) then
if (iSpLeft <= Image1.Clientwidth - iSpwidth - 10) then
iSpLeft := iSpLeft + 10;
if (GetKeyState(VK_UP) < 0) then
if (iSpTop >= 10) then
iSpTop := iSpTop - 10;
if (GetKeyState(VK_DOWN) < 0) then
if (iSpTop <= Image1.ClientHeight - iSpHeight - 10) then
iSpTop := iSpTop + 10;
imgBuffer.Assign(imgBackground); // Write Background to Buffer
Imagelist1.Draw(imgBuffer.Canvas, iSpLeft, iSpTop, 0, True); // Draw Sprite to Buffer.
Image1.Picture.Assign(imgBuffer); // Paint new image in Buffer to screen
end;
If anyone has the time could they please check the attached program? I suspect an error in the LCL, but it needs an independent check before I file a bug report.