Fixed bug 4043 - SDL_windowswindow.c incorrect icon height
authorSam Lantinga <slouken@libsdl.org>
Mon, 15 Jan 2018 10:29:53 -0800
changeset 1182544536468cdd2
parent 11824 00fb5966c44f
child 11826 13d922b387db
Fixed bug 4043 - SDL_windowswindow.c incorrect icon height

Needed to allocate space for the mask in the ICONIMAGE structure
src/video/windows/SDL_windowswindow.c
     1.1 --- a/src/video/windows/SDL_windowswindow.c	Wed Jan 10 18:00:51 2018 -0800
     1.2 +++ b/src/video/windows/SDL_windowswindow.c	Mon Jan 15 10:29:53 2018 -0800
     1.3 @@ -438,11 +438,12 @@
     1.4      HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
     1.5      HICON hicon = NULL;
     1.6      BYTE *icon_bmp;
     1.7 -    int icon_len, y;
     1.8 +    int icon_len, mask_len, y;
     1.9      SDL_RWops *dst;
    1.10  
    1.11 -    /* Create temporary bitmap buffer */
    1.12 -    icon_len = 40 + icon->h * icon->w * sizeof(Uint32);
    1.13 +    /* Create temporary buffer for ICONIMAGE structure */
    1.14 +    mask_len = (icon->h * (icon->w + 7)/8);
    1.15 +    icon_len = 40 + icon->h * icon->w * sizeof(Uint32) + mask_len;
    1.16      icon_bmp = SDL_stack_alloc(BYTE, icon_len);
    1.17      dst = SDL_RWFromMem(icon_bmp, icon_len);
    1.18      if (!dst) {
    1.19 @@ -471,6 +472,9 @@
    1.20          SDL_RWwrite(dst, src, icon->w * sizeof(Uint32), 1);
    1.21      }
    1.22  
    1.23 +    /* Write the mask */
    1.24 +    SDL_memset(icon_bmp + icon_len - mask_len, 0xFF, mask_len);
    1.25 +
    1.26      hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
    1.27  
    1.28      SDL_RWclose(dst);