[FIXED] Icon: Premature destroying

Started by Simon Felix, April 08, 2011, 09:20:50

Previous topic - Next topic

Simon Felix

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():

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

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
Download Cultris II, the fastest Tetris clone from http://gewaltig.net/