Hello Guest

[FIXED] Icon: Premature destroying

  • 0 Replies
  • 4011 Views
[FIXED] Icon: Premature destroying
« on: April 08, 2011, 09:20:50 »
Hello everyone

We're trying to show animated window icons in our game. The animation flickers... When debugging this I noticed a bug in the code when setting a new icon. In WindowsDisplay.java, function setIcon():

Code: [Select]
freeSmallIcon();
small_icon = createIcon(small_icon_size, small_icon_size, icon.asIntBuffer());
sendMessage(hwnd, WM_SETICON, ICON_SMALL, small_icon);

As you can see it first calls freeSmallIcon() (or freeLargeIcon()) before setting the new icon. This function in the end calls DestroyIcon. The documentation of this function states that "The icon must not be in use.".

Ideally the code should therefore be written like this

Code: [Select]
long new_icon = createIcon(small_icon_size, small_icon_size, icon.asIntBuffer());
sendMessage(hwnd, WM_SETICON, ICON_SMALL, new_icon);
freeSmallIcon();
small_icon = new_icon;

and similarily for large_icon a few lines below.

Cheers,
Simon
« Last Edit: April 08, 2011, 17:48:23 by dr_evil »
Download Cultris II, the fastest Tetris clone from http://gewaltig.net/