Couriersud fixed bug #603
authorSam Lantinga <slouken@libsdl.org>
Tue, 26 Aug 2008 02:47:26 +0000
changeset 2723911db724ea24
parent 2722 91f1706b27be
child 2724 0e2b65f32298
Couriersud fixed bug #603

Using the following sequence

SDL_Init(..:)
SDL_CreateWindow(..., SDL_WINDOW_OPENGL)
SDL_DestroyWindow
SDL_CreateWindow(..., SDL_WINDOW_OPENGL)

SDL will crash in X11_GL_GetVisual. This is due to the fact that
during SDL_DestroyWindow X11_GL_Shutdown was called because the last window
has been closed.

On the next call to SDL_CreateWindow the library is still loaded and only the
memory is reinitialized. Function pointers such as gl_data->glXChooseVisual
will not be reinitialized.

Consequently, SDL will crash due to a NULL pointer access.

The attached patch corrects the behaviour.
src/video/x11/SDL_x11opengl.c
     1.1 --- a/src/video/x11/SDL_x11opengl.c	Tue Aug 26 02:40:24 2008 +0000
     1.2 +++ b/src/video/x11/SDL_x11opengl.c	Tue Aug 26 02:47:26 2008 +0000
     1.3 @@ -73,26 +73,26 @@
     1.4      void *handle;
     1.5  
     1.6      if (_this->gl_config.driver_loaded) {
     1.7 +        /* do not return without reinitializing the function hooks */
     1.8          if (path) {
     1.9              SDL_SetError("OpenGL library already loaded");
    1.10 +        }
    1.11 +        handle = _this->gl_config.dll_handle;
    1.12 +    } else {
    1.13 +        if (path == NULL) {
    1.14 +            path = SDL_getenv("SDL_OPENGL_LIBRARY");
    1.15 +        }
    1.16 +        if (path == NULL) {
    1.17 +            path = DEFAULT_OPENGL;
    1.18 +        }
    1.19 +        handle = GL_LoadObject(path);
    1.20 +        if (!handle) {
    1.21              return -1;
    1.22 -        } else {
    1.23 -            ++_this->gl_config.driver_loaded;
    1.24 -            return 0;
    1.25          }
    1.26 -    }
    1.27 -    if (path == NULL) {
    1.28 -        path = SDL_getenv("SDL_OPENGL_LIBRARY");
    1.29 +        _this->gl_config.dll_handle = handle;
    1.30 +        SDL_strlcpy(_this->gl_config.driver_path, path,
    1.31 +                    SDL_arraysize(_this->gl_config.driver_path));
    1.32      }
    1.33 -    if (path == NULL) {
    1.34 -        path = DEFAULT_OPENGL;
    1.35 -    }
    1.36 -    handle = GL_LoadObject(path);
    1.37 -    if (!handle) {
    1.38 -        return -1;
    1.39 -    }
    1.40 -    // LoadLibrary may be called before WindowCreate!
    1.41 -    // Must create the memory used by GL
    1.42      X11_GL_InitializeMemory(_this);
    1.43  
    1.44      /* Load new function pointers */
    1.45 @@ -123,10 +123,7 @@
    1.46          return -1;
    1.47      }
    1.48  
    1.49 -    _this->gl_config.dll_handle = handle;
    1.50 -    SDL_strlcpy(_this->gl_config.driver_path, path,
    1.51 -                SDL_arraysize(_this->gl_config.driver_path));
    1.52 -    _this->gl_config.driver_loaded = 1;
    1.53 +    ++_this->gl_config.driver_loaded;
    1.54      return 0;
    1.55  }
    1.56