Fixed bug 1313 - Segfault on SDL_CreateWindow when gl lib cannot be loaded
authorSam Lantinga <slouken@libsdl.org>
Sat, 07 Jan 2012 23:33:15 -0500
changeset 6181 e29f01fa2750
parent 6180 744ae9bdf5da
child 6182 eb6796f3e598
Fixed bug 1313 - Segfault on SDL_CreateWindow when gl lib cannot be loaded Don't crash if the gl_data isn't valid, just return NULL.
src/video/x11/SDL_x11opengl.c
--- a/src/video/x11/SDL_x11opengl.c	Sat Jan 07 22:52:41 2012 -0500
+++ b/src/video/x11/SDL_x11opengl.c	Sat Jan 07 23:33:15 2012 -0500
@@ -187,8 +187,10 @@
 #endif
 
     /* Free OpenGL memory */
-    SDL_free(_this->gl_data);
-    _this->gl_data = NULL;
+    if (_this->gl_data) {
+        SDL_free(_this->gl_data);
+        _this->gl_data = NULL;
+    }
 }
 
 static SDL_bool
@@ -396,6 +398,11 @@
     const int i = X11_GL_GetAttributes(_this,display,screen,attribs,max_attrs);
     SDL_assert(i <= max_attrs);
 
+    if (!_this->gl_data) {
+        /* The OpenGL library wasn't loaded, SDL_GetError() should have info */
+        return NULL;
+    }
+
     vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs);
     if (!vinfo) {
         SDL_SetError("Couldn't find matching GLX visual");