Commit b7b6d8ab7a6f2c3231a647a34e9dcc048eee8604

Sam Lantinga 2014-06-22T02:30:36

Fixed crash initializing OpenGL ES renderer if OpenGL renderer fails

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 2a6de10..2e097d0 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -1402,7 +1402,7 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
 
     if (_this->CreateWindow && !(flags & SDL_WINDOW_FOREIGN)) {
         if (_this->CreateWindow(_this, window) < 0) {
-            if (flags & SDL_WINDOW_OPENGL) {
+            if ((flags & SDL_WINDOW_OPENGL) && !(window->flags & SDL_WINDOW_OPENGL)) {
                 SDL_GL_UnloadLibrary();
             }
             return -1;
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 71f7bb6..e9364d8 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -1488,6 +1488,8 @@ Cocoa_DestroyWindow(_THIS, SDL_Window * window)
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
 
+    window->driverdata = NULL;
+
     if (data) {
         [data->listener close];
         [data->listener release];
diff --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m
index a805227..b6c1a0d 100644
--- a/src/video/uikit/SDL_uikitwindow.m
+++ b/src/video/uikit/SDL_uikitwindow.m
@@ -289,11 +289,13 @@ void
 UIKit_DestroyWindow(_THIS, SDL_Window * window)
 {
     SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
+
+    window->driverdata = NULL;
+
     if (data) {
         [data->viewcontroller release];
         [data->uiwindow release];
         SDL_free(data);
-        window->driverdata = NULL;
     }
 }
 
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index 8ff85a3..0cbfe78 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -619,6 +619,8 @@ WIN_DestroyWindow(_THIS, SDL_Window * window)
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
 
+    window->driverdata = NULL;
+
     if (data) {
         ReleaseDC(data->hwnd, data->hdc);
         if (data->created) {
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index 5c5bdd6..2eccd27 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -1393,6 +1393,7 @@ void
 X11_DestroyWindow(_THIS, SDL_Window * window)
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
     window->driverdata = NULL;
 
     if (data) {