Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing using TPaintBox 1

Status
Not open for further replies.

ChessPro

Programmer
Feb 20, 2006
14
US
I’ve built software which animates a chess game showing the sliding movements of the pieces in a designated area of the main window. I use TPaintBox component for that purpose passing a TBitmap to TPaintBox.Canvas.Draw as a parameter.
Sometimes the picture freezes when I move the cursor during the animation process. The process in whole continues: the program reads the game move by move, but the image of the chess board doesn’t change. It seems TPaintBox loses the bitmap at that moment. I experimented a lot working on the function, which actually implements the process of drawing of the chess pieces movement on the board. Once I added a line, which had no direct relation to the animation and merely wrote the move information to a TMemo, such as move number, etc. And miraculously the picture stopped freezing! Later I redesigned the program interface and that TMemo became no longer useful. But I’ve left it, setting its Visible property to False, because it somehow helps to avoid the freezing of animation!
Not that that TMemo bothers me much, but in general I don’t like useless code and I want to understand the nature of the problem. I suspect that there might be a problem with Windows GDI resources (I use Windows XP).
 
Are you drawing in a thread other than the main one? If so, lock the canvas while drawing.

Your symptoms are tipical of a) thread synchronization problems or b) corrupted memory problems.

buho (A).

 
Thank you, Buho!
Locking the canvas solved the problem. I am using Multimedia Timer to emulate animation and didn’t consider that it runs in its own thread.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top