Fixed bug 4043 - SDL_windowswindow.c incorrect icon height

Needed to allocate space for the mask in the ICONIMAGE structure
Sam Lantinga 2018-01-15 10:29:53 -08:00
parent a0c4eb2aa3
commit 0cba684794
1 changed files with 7 additions and 3 deletions

View File

@ -438,11 +438,12 @@ WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd; HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
HICON hicon = NULL; HICON hicon = NULL;
BYTE *icon_bmp; BYTE *icon_bmp;
int icon_len, y; int icon_len, mask_len, y;
SDL_RWops *dst; SDL_RWops *dst;
/* Create temporary bitmap buffer */ /* Create temporary buffer for ICONIMAGE structure */
icon_len = 40 + icon->h * icon->w * sizeof(Uint32); mask_len = (icon->h * (icon->w + 7)/8);
icon_len = 40 + icon->h * icon->w * sizeof(Uint32) + mask_len;
icon_bmp = SDL_stack_alloc(BYTE, icon_len); icon_bmp = SDL_stack_alloc(BYTE, icon_len);
dst = SDL_RWFromMem(icon_bmp, icon_len); dst = SDL_RWFromMem(icon_bmp, icon_len);
if (!dst) { if (!dst) {
@ -471,6 +472,9 @@ WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
SDL_RWwrite(dst, src, icon->w * sizeof(Uint32), 1); SDL_RWwrite(dst, src, icon->w * sizeof(Uint32), 1);
} }
/* Write the mask */
SDL_memset(icon_bmp + icon_len - mask_len, 0xFF, mask_len);
hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000); hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
SDL_RWclose(dst); SDL_RWclose(dst);