Fixed bug 1919 - Window icon disappears as soon as a renderer is created
authorSam Lantinga <slouken@libsdl.org>
Sun, 14 Jul 2013 18:17:28 -0700
changeset 75239e9ab1dc3811
parent 7522 b186724247dd
child 7524 6d8fd70e1477
Fixed bug 1919 - Window icon disappears as soon as a renderer is created

Sebastian

Setting a window icon works just fine until a renderer is added to the window.
After adding the renderer the icon disappears.

Reproduce by:
- Take the example code from the wiki: http://wiki.libsdl.org/moin.fcg/SDL_SetWindowIcon

- Add the following two lines after SDL_FreeSurface(surface);
SDL_Delay(1000);
SDL_Renderer* ren = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);

-compile and run

You will see the window icon correctly at first. After the Delay the Icon will disappear.
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/windows/SDL_windowswindow.c
src/video/x11/SDL_x11window.c
     1.1 --- a/src/video/SDL_sysvideo.h	Sat Jul 27 00:49:34 2013 -0700
     1.2 +++ b/src/video/SDL_sysvideo.h	Sun Jul 14 18:17:28 2013 -0700
     1.3 @@ -73,6 +73,7 @@
     1.4      const void *magic;
     1.5      Uint32 id;
     1.6      char *title;
     1.7 +    SDL_Surface *icon;
     1.8      int x, y;
     1.9      int w, h;
    1.10      int min_w, min_h;
     2.1 --- a/src/video/SDL_video.c	Sat Jul 27 00:49:34 2013 -0700
     2.2 +++ b/src/video/SDL_video.c	Sun Jul 14 18:17:28 2013 -0700
     2.3 @@ -1297,6 +1297,7 @@
     2.4  SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
     2.5  {
     2.6      char *title = window->title;
     2.7 +    SDL_Surface *icon = window->icon;
     2.8  
     2.9      if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
    2.10          return SDL_SetError("No OpenGL support in video driver");
    2.11 @@ -1335,6 +1336,7 @@
    2.12      }
    2.13  
    2.14      window->title = NULL;
    2.15 +    window->icon = NULL;
    2.16      window->flags = ((flags & CREATE_FLAGS) | SDL_WINDOW_HIDDEN);
    2.17  
    2.18      if (_this->CreateWindow && !(flags & SDL_WINDOW_FOREIGN)) {
    2.19 @@ -1350,6 +1352,10 @@
    2.20          SDL_SetWindowTitle(window, title);
    2.21          SDL_free(title);
    2.22      }
    2.23 +    if (icon) {
    2.24 +        SDL_SetWindowIcon(window, icon);
    2.25 +        SDL_FreeSurface(icon);
    2.26 +    }
    2.27      SDL_FinishWindowCreation(window, flags);
    2.28  
    2.29      return 0;
    2.30 @@ -1426,8 +1432,18 @@
    2.31          return;
    2.32      }
    2.33  
    2.34 +    if (window->icon) {
    2.35 +        SDL_FreeSurface(window->icon);
    2.36 +    }
    2.37 +
    2.38 +    /* Convert the icon into ARGB8888 */
    2.39 +    window->icon = SDL_ConvertSurfaceFormat(icon, SDL_PIXELFORMAT_ARGB8888, 0);
    2.40 +    if (!window->icon) {
    2.41 +        return;
    2.42 +    }
    2.43 +
    2.44      if (_this->SetWindowIcon) {
    2.45 -        _this->SetWindowIcon(_this, window, icon);
    2.46 +        _this->SetWindowIcon(_this, window, window->icon);
    2.47      }
    2.48  }
    2.49  
    2.50 @@ -2167,6 +2183,9 @@
    2.51      if (window->title) {
    2.52          SDL_free(window->title);
    2.53      }
    2.54 +    if (window->icon) {
    2.55 +        SDL_FreeSurface(window->icon);
    2.56 +    }
    2.57      if (window->gamma) {
    2.58          SDL_free(window->gamma);
    2.59      }
     3.1 --- a/src/video/windows/SDL_windowswindow.c	Sat Jul 27 00:49:34 2013 -0700
     3.2 +++ b/src/video/windows/SDL_windowswindow.c	Sun Jul 14 18:17:28 2013 -0700
     3.3 @@ -22,6 +22,7 @@
     3.4  
     3.5  #if SDL_VIDEO_DRIVER_WINDOWS
     3.6  
     3.7 +#include "SDL_assert.h"
     3.8  #include "../SDL_sysvideo.h"
     3.9  #include "../SDL_pixels_c.h"
    3.10  #include "../../events/SDL_keyboard_c.h"
    3.11 @@ -292,7 +293,6 @@
    3.12      BYTE *icon_bmp;
    3.13      int icon_len;
    3.14      SDL_RWops *dst;
    3.15 -    SDL_Surface *surface;
    3.16  
    3.17      /* Create temporary bitmap buffer */
    3.18      icon_len = 40 + icon->h * icon->w * 4;
    3.19 @@ -316,19 +316,16 @@
    3.20      SDL_WriteLE32(dst, 0);
    3.21      SDL_WriteLE32(dst, 0);
    3.22  
    3.23 -    /* Convert the icon to a 32-bit surface with alpha channel */
    3.24 -    surface = SDL_ConvertSurfaceFormat(icon, SDL_PIXELFORMAT_ARGB8888, 0);
    3.25 -    if (surface) {
    3.26 -        /* Write the pixels upside down into the bitmap buffer */
    3.27 -        int y = surface->h;
    3.28 -        while (y--) {
    3.29 -            Uint8 *src = (Uint8 *) surface->pixels + y * surface->pitch;
    3.30 -            SDL_RWwrite(dst, src, surface->pitch, 1);
    3.31 -        }
    3.32 -        SDL_FreeSurface(surface);
    3.33 +    /* Write the pixels upside down into the bitmap buffer */
    3.34 +    SDL_assert(icon->format->format == SDL_PIXELFORMAT_ARGB8888);
    3.35 +    int y = icon->h;
    3.36 +    while (y--) {
    3.37 +        Uint8 *src = (Uint8 *) icon->pixels + y * icon->pitch;
    3.38 +        SDL_RWwrite(dst, src, icon->pitch, 1);
    3.39 +    }
    3.40  
    3.41 -        hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
    3.42 -    }
    3.43 +    hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
    3.44 +
    3.45      SDL_RWclose(dst);
    3.46      SDL_stack_free(icon_bmp);
    3.47  
     4.1 --- a/src/video/x11/SDL_x11window.c	Sat Jul 27 00:49:34 2013 -0700
     4.2 +++ b/src/video/x11/SDL_x11window.c	Sun Jul 14 18:17:28 2013 -0700
     4.3 @@ -22,6 +22,7 @@
     4.4  
     4.5  #if SDL_VIDEO_DRIVER_X11
     4.6  
     4.7 +#include "SDL_assert.h"
     4.8  #include "SDL_hints.h"
     4.9  #include "../SDL_sysvideo.h"
    4.10  #include "../SDL_pixels_c.h"
    4.11 @@ -698,19 +699,11 @@
    4.12      Atom _NET_WM_ICON = data->videodata->_NET_WM_ICON;
    4.13  
    4.14      if (icon) {
    4.15 -        SDL_PixelFormat format;
    4.16 -        SDL_Surface *surface;
    4.17          int propsize;
    4.18          long *propdata;
    4.19  
    4.20 -        /* Convert the icon to ARGB for modern window managers */
    4.21 -        SDL_InitFormat(&format, SDL_PIXELFORMAT_ARGB8888);
    4.22 -        surface = SDL_ConvertSurface(icon, &format, 0);
    4.23 -        if (!surface) {
    4.24 -            return;
    4.25 -        }
    4.26 -
    4.27          /* Set the _NET_WM_ICON property */
    4.28 +        SDL_assert(icon->format->format == SDL_PIXELFORMAT_ARGB8888);
    4.29          propsize = 2 + (icon->w * icon->h);
    4.30          propdata = SDL_malloc(propsize * sizeof(long));
    4.31          if (propdata) {
    4.32 @@ -722,7 +715,7 @@
    4.33              propdata[1] = icon->h;
    4.34              dst = &propdata[2];
    4.35              for (y = 0; y < icon->h; ++y) {
    4.36 -                src = (Uint32*)((Uint8*)surface->pixels + y * surface->pitch);
    4.37 +                src = (Uint32*)((Uint8*)icon->pixels + y * icon->pitch);
    4.38                  for (x = 0; x < icon->w; ++x) {
    4.39                      *dst++ = *src++;
    4.40                  }
    4.41 @@ -732,7 +725,6 @@
    4.42                              propsize);
    4.43          }
    4.44          SDL_free(propdata);
    4.45 -        SDL_FreeSurface(surface);
    4.46      } else {
    4.47          XDeleteProperty(display, data->xwindow, _NET_WM_ICON);
    4.48      }