Fixed bug 1313 - Segfault on SDL_CreateWindow when gl lib cannot be loaded
authorSam Lantinga
Sat, 07 Jan 2012 23:33:15 -0500
changeset 6181e29f01fa2750
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
     1.1 --- a/src/video/x11/SDL_x11opengl.c	Sat Jan 07 22:52:41 2012 -0500
     1.2 +++ b/src/video/x11/SDL_x11opengl.c	Sat Jan 07 23:33:15 2012 -0500
     1.3 @@ -187,8 +187,10 @@
     1.4  #endif
     1.5  
     1.6      /* Free OpenGL memory */
     1.7 -    SDL_free(_this->gl_data);
     1.8 -    _this->gl_data = NULL;
     1.9 +    if (_this->gl_data) {
    1.10 +        SDL_free(_this->gl_data);
    1.11 +        _this->gl_data = NULL;
    1.12 +    }
    1.13  }
    1.14  
    1.15  static SDL_bool
    1.16 @@ -396,6 +398,11 @@
    1.17      const int i = X11_GL_GetAttributes(_this,display,screen,attribs,max_attrs);
    1.18      SDL_assert(i <= max_attrs);
    1.19  
    1.20 +    if (!_this->gl_data) {
    1.21 +        /* The OpenGL library wasn't loaded, SDL_GetError() should have info */
    1.22 +        return NULL;
    1.23 +    }
    1.24 +
    1.25      vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs);
    1.26      if (!vinfo) {
    1.27          SDL_SetError("Couldn't find matching GLX visual");