Fixed crash initializing OpenGL ES renderer if OpenGL renderer fails
authorSam Lantinga <slouken@libsdl.org>
Sun, 22 Jun 2014 02:30:36 -0700
changeset 8905 1519c462cee6
parent 8904 c38e754cafd3
child 8906 c8da136e2a83
Fixed crash initializing OpenGL ES renderer if OpenGL renderer fails
src/video/SDL_video.c
src/video/cocoa/SDL_cocoawindow.m
src/video/uikit/SDL_uikitwindow.m
src/video/windows/SDL_windowswindow.c
src/video/x11/SDL_x11window.c
--- a/src/video/SDL_video.c	Sat Jun 21 21:46:42 2014 -0700
+++ b/src/video/SDL_video.c	Sun Jun 22 02:30:36 2014 -0700
@@ -1402,7 +1402,7 @@
 
     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;
--- a/src/video/cocoa/SDL_cocoawindow.m	Sat Jun 21 21:46:42 2014 -0700
+++ b/src/video/cocoa/SDL_cocoawindow.m	Sun Jun 22 02:30:36 2014 -0700
@@ -1488,6 +1488,8 @@
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
 
+    window->driverdata = NULL;
+
     if (data) {
         [data->listener close];
         [data->listener release];
--- a/src/video/uikit/SDL_uikitwindow.m	Sat Jun 21 21:46:42 2014 -0700
+++ b/src/video/uikit/SDL_uikitwindow.m	Sun Jun 22 02:30:36 2014 -0700
@@ -289,11 +289,13 @@
 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;
     }
 }
 
--- a/src/video/windows/SDL_windowswindow.c	Sat Jun 21 21:46:42 2014 -0700
+++ b/src/video/windows/SDL_windowswindow.c	Sun Jun 22 02:30:36 2014 -0700
@@ -619,6 +619,8 @@
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
 
+    window->driverdata = NULL;
+
     if (data) {
         ReleaseDC(data->hwnd, data->hdc);
         if (data->created) {
--- a/src/video/x11/SDL_x11window.c	Sat Jun 21 21:46:42 2014 -0700
+++ b/src/video/x11/SDL_x11window.c	Sun Jun 22 02:30:36 2014 -0700
@@ -1393,6 +1393,7 @@
 X11_DestroyWindow(_THIS, SDL_Window * window)
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
     window->driverdata = NULL;
 
     if (data) {