Commit 4dd047e9 authored by Sam Lantinga's avatar Sam Lantinga

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.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403174
parent 4dd96455
...@@ -73,14 +73,12 @@ X11_GL_LoadLibrary(_THIS, const char *path) ...@@ -73,14 +73,12 @@ X11_GL_LoadLibrary(_THIS, const char *path)
void *handle; void *handle;
if (_this->gl_config.driver_loaded) { if (_this->gl_config.driver_loaded) {
/* do not return without reinitializing the function hooks */
if (path) { if (path) {
SDL_SetError("OpenGL library already loaded"); SDL_SetError("OpenGL library already loaded");
return -1;
} else {
++_this->gl_config.driver_loaded;
return 0;
}
} }
handle = _this->gl_config.dll_handle;
} else {
if (path == NULL) { if (path == NULL) {
path = SDL_getenv("SDL_OPENGL_LIBRARY"); path = SDL_getenv("SDL_OPENGL_LIBRARY");
} }
...@@ -91,8 +89,10 @@ X11_GL_LoadLibrary(_THIS, const char *path) ...@@ -91,8 +89,10 @@ X11_GL_LoadLibrary(_THIS, const char *path)
if (!handle) { if (!handle) {
return -1; return -1;
} }
// LoadLibrary may be called before WindowCreate! _this->gl_config.dll_handle = handle;
// Must create the memory used by GL SDL_strlcpy(_this->gl_config.driver_path, path,
SDL_arraysize(_this->gl_config.driver_path));
}
X11_GL_InitializeMemory(_this); X11_GL_InitializeMemory(_this);
/* Load new function pointers */ /* Load new function pointers */
...@@ -123,10 +123,7 @@ X11_GL_LoadLibrary(_THIS, const char *path) ...@@ -123,10 +123,7 @@ X11_GL_LoadLibrary(_THIS, const char *path)
return -1; return -1;
} }
_this->gl_config.dll_handle = handle; ++_this->gl_config.driver_loaded;
SDL_strlcpy(_this->gl_config.driver_path, path,
SDL_arraysize(_this->gl_config.driver_path));
_this->gl_config.driver_loaded = 1;
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment