Saturday, November 12, 2005

Corrupted Custom Cursor Conundrum

It's a pity I don't have champagne, because two nasty bugs have been squashed.

Moyo Go uses custom cursors to show what you're doing. When annotating board labels with green letters for example, and you have just put an "A" and a "B" on the board, the cursor is a little hand with a green "C" underneath an outstretched finger, because the next time you click the board, a green "C" will appear.

This is of course highly cool.

For some weird reason however, the cursor, at startup, looked "corrupted". Sometimes. It became partially a fuchsia color, or it got a photo-negative kind of appearance. I looked at my code and it seemed OK.

Little did I know that Delphi's Bitmap Canvas objects were not threadsafe, and that right in the middle of a loop that made the custom cursor's transparency mask, its handle would become invalid!

I solved it by putting a "canvas lock" around the loop.