# HG changeset patch # User Sam Lantinga # Date 1219718846 0 # Node ID 911db724ea24870b6ea49a5c7dd89be8bc8c445f # Parent 91f1706b27be912cff80dae7c8958878d5a5e95b 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. diff -r 91f1706b27be -r 911db724ea24 src/video/x11/SDL_x11opengl.c --- a/src/video/x11/SDL_x11opengl.c Tue Aug 26 02:40:24 2008 +0000 +++ b/src/video/x11/SDL_x11opengl.c Tue Aug 26 02:47:26 2008 +0000 @@ -73,26 +73,26 @@ void *handle; if (_this->gl_config.driver_loaded) { + /* do not return without reinitializing the function hooks */ if (path) { SDL_SetError("OpenGL library already loaded"); + } + handle = _this->gl_config.dll_handle; + } else { + if (path == NULL) { + path = SDL_getenv("SDL_OPENGL_LIBRARY"); + } + if (path == NULL) { + path = DEFAULT_OPENGL; + } + handle = GL_LoadObject(path); + if (!handle) { return -1; - } else { - ++_this->gl_config.driver_loaded; - return 0; } - } - if (path == NULL) { - path = SDL_getenv("SDL_OPENGL_LIBRARY"); + _this->gl_config.dll_handle = handle; + SDL_strlcpy(_this->gl_config.driver_path, path, + SDL_arraysize(_this->gl_config.driver_path)); } - if (path == NULL) { - path = DEFAULT_OPENGL; - } - handle = GL_LoadObject(path); - if (!handle) { - return -1; - } - // LoadLibrary may be called before WindowCreate! - // Must create the memory used by GL X11_GL_InitializeMemory(_this); /* Load new function pointers */ @@ -123,10 +123,7 @@ return -1; } - _this->gl_config.dll_handle = handle; - SDL_strlcpy(_this->gl_config.driver_path, path, - SDL_arraysize(_this->gl_config.driver_path)); - _this->gl_config.driver_loaded = 1; + ++_this->gl_config.driver_loaded; return 0; }