Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Couriersud fixed bug #603
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slouken committed Aug 26, 2008
1 parent dc5bfa5 commit d301cad
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/video/x11/SDL_x11opengl.c
Expand Up @@ -73,26 +73,26 @@ X11_GL_LoadLibrary(_THIS, const char *path)
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;
}
_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 = SDL_getenv("SDL_OPENGL_LIBRARY");
}
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 */
Expand Down Expand Up @@ -123,10 +123,7 @@ X11_GL_LoadLibrary(_THIS, const char *path)
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;
}

Expand Down

0 comments on commit d301cad

Please sign in to comment.