Fixed bug #1116
authorSam Lantinga
Sat, 12 Feb 2011 17:51:47 -0800
changeset 5275bad04e4710f6
parent 5274 07559b6cb64f
child 5276 8e421890cdb8
child 5282 15a71bec4a55
Fixed bug #1116

Don't allocate the window's texture data until after creating the renderer, in case the renderer recreates the window.
src/video/SDL_video.c
     1.1 --- a/src/video/SDL_video.c	Sat Feb 12 17:36:09 2011 -0800
     1.2 +++ b/src/video/SDL_video.c	Sat Feb 12 17:51:47 2011 -0800
     1.3 @@ -214,16 +214,6 @@
     1.4  
     1.5      data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
     1.6      if (!data) {
     1.7 -        data = (SDL_WindowTextureData *)SDL_calloc(1, sizeof(*data));
     1.8 -        if (!data) {
     1.9 -            SDL_OutOfMemory();
    1.10 -            return -1;
    1.11 -        }
    1.12 -        SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, data);
    1.13 -    }
    1.14 -
    1.15 -    renderer = data->renderer;
    1.16 -    if (!renderer) {
    1.17          SDL_RendererInfo info;
    1.18          int i;
    1.19          const char *hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
    1.20 @@ -254,6 +244,16 @@
    1.21          if (!renderer) {
    1.22              return -1;
    1.23          }
    1.24 +
    1.25 +        /* Create the data after we successfully create the renderer (bug #1116) */
    1.26 +        data = (SDL_WindowTextureData *)SDL_calloc(1, sizeof(*data));
    1.27 +        if (!data) {
    1.28 +            SDL_DestroyRenderer(renderer);
    1.29 +            SDL_OutOfMemory();
    1.30 +            return -1;
    1.31 +        }
    1.32 +        SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, data);
    1.33 +
    1.34          data->renderer = renderer;
    1.35      }
    1.36