From 5b2a5e34122c74755c427abb12d30dcca7dcdb44 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 7 Jan 2012 23:33:15 -0500 Subject: [PATCH] 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 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index faec60583..63cb6c858 100755 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -187,8 +187,10 @@ X11_GL_UnloadLibrary(_THIS) #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 @@ X11_GL_GetVisual(_THIS, Display * display, int screen) 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");