Fixed bug #1116
authorSam Lantinga <slouken@libsdl.org>
Sat, 12 Feb 2011 17:51:47 -0800
changeset 5275 bad04e4710f6
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
--- a/src/video/SDL_video.c	Sat Feb 12 17:36:09 2011 -0800
+++ b/src/video/SDL_video.c	Sat Feb 12 17:51:47 2011 -0800
@@ -214,16 +214,6 @@
 
     data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
     if (!data) {
-        data = (SDL_WindowTextureData *)SDL_calloc(1, sizeof(*data));
-        if (!data) {
-            SDL_OutOfMemory();
-            return -1;
-        }
-        SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, data);
-    }
-
-    renderer = data->renderer;
-    if (!renderer) {
         SDL_RendererInfo info;
         int i;
         const char *hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
@@ -254,6 +244,16 @@
         if (!renderer) {
             return -1;
         }
+
+        /* Create the data after we successfully create the renderer (bug #1116) */
+        data = (SDL_WindowTextureData *)SDL_calloc(1, sizeof(*data));
+        if (!data) {
+            SDL_DestroyRenderer(renderer);
+            SDL_OutOfMemory();
+            return -1;
+        }
+        SDL_SetWindowData(window, SDL_WINDOWTEXTUREDATA, data);
+
         data->renderer = renderer;
     }