Fixed bug 2629 - Mac: crash when calling SDL_DestroyWindow with an active OpenGL context

Alex Szpakowski

Since this commit https://hg.libsdl.org/SDL/rev/59b543340d63 , calling SDL_DestroyWindow will crash the program if the window has an active OpenGL context.

This is because the Cocoa_DestroyWindow code sets the window's driverdata to NULL and then calls [context setWindow:NULL], which tries to access the window's driverdata, resulting in a null pointer dereference.

I have attached a patch which fixes the issue by moving the line which sets the driverdata to NULL to after the lines which call functions that use the driverdata pointer.
Sam Lantinga 2014-07-07 10:33:32 -07:00
parent 1c6cd67819
commit d44f392265
6 changed files with 7 additions and 12 deletions

View File

@ -1544,8 +1544,6 @@ Cocoa_DestroyWindow(_THIS, SDL_Window * window)
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDL_WindowData *data = (SDL_WindowData *) window->driverdata; SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
window->driverdata = NULL;
if (data) { if (data) {
[data->listener close]; [data->listener close];
[data->listener release]; [data->listener release];
@ -1562,6 +1560,8 @@ Cocoa_DestroyWindow(_THIS, SDL_Window * window)
SDL_free(data); SDL_free(data);
} }
window->driverdata = NULL;
[pool release]; [pool release];
} }

View File

@ -149,14 +149,13 @@ MIR_DestroyWindow(_THIS, SDL_Window* window)
MIR_Data* mir_data = _this->driverdata; MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window = window->driverdata; MIR_Window* mir_window = window->driverdata;
window->driverdata = NULL;
if (mir_data) { if (mir_data) {
SDL_EGL_DestroySurface(_this, mir_window->egl_surface); SDL_EGL_DestroySurface(_this, mir_window->egl_surface);
MIR_mir_surface_release_sync(mir_window->surface); MIR_mir_surface_release_sync(mir_window->surface);
SDL_free(mir_window); SDL_free(mir_window);
} }
window->driverdata = NULL;
} }
SDL_bool SDL_bool

View File

@ -290,13 +290,12 @@ UIKit_DestroyWindow(_THIS, SDL_Window * window)
{ {
SDL_WindowData *data = (SDL_WindowData *)window->driverdata; SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
window->driverdata = NULL;
if (data) { if (data) {
[data->viewcontroller release]; [data->viewcontroller release];
[data->uiwindow release]; [data->uiwindow release];
SDL_free(data); SDL_free(data);
} }
window->driverdata = NULL;
} }
SDL_bool SDL_bool

View File

@ -243,8 +243,6 @@ void Wayland_DestroyWindow(_THIS, SDL_Window *window)
SDL_VideoData *data = _this->driverdata; SDL_VideoData *data = _this->driverdata;
SDL_WindowData *wind = window->driverdata; SDL_WindowData *wind = window->driverdata;
window->driverdata = NULL;
if (data) { if (data) {
SDL_EGL_DestroySurface(_this, wind->egl_surface); SDL_EGL_DestroySurface(_this, wind->egl_surface);
WAYLAND_wl_egl_window_destroy(wind->egl_window); WAYLAND_wl_egl_window_destroy(wind->egl_window);
@ -261,6 +259,7 @@ void Wayland_DestroyWindow(_THIS, SDL_Window *window)
SDL_free(wind); SDL_free(wind);
WAYLAND_wl_display_flush(data->display); WAYLAND_wl_display_flush(data->display);
} }
window->driverdata = NULL;
} }
#endif /* SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL */ #endif /* SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL */

View File

@ -619,8 +619,6 @@ WIN_DestroyWindow(_THIS, SDL_Window * window)
{ {
SDL_WindowData *data = (SDL_WindowData *) window->driverdata; SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
window->driverdata = NULL;
if (data) { if (data) {
ReleaseDC(data->hwnd, data->hdc); ReleaseDC(data->hwnd, data->hdc);
if (data->created) { if (data->created) {
@ -639,6 +637,7 @@ WIN_DestroyWindow(_THIS, SDL_Window * window)
} }
SDL_free(data); SDL_free(data);
} }
window->driverdata = NULL;
} }
SDL_bool SDL_bool

View File

@ -1394,8 +1394,6 @@ X11_DestroyWindow(_THIS, SDL_Window * window)
{ {
SDL_WindowData *data = (SDL_WindowData *) window->driverdata; SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
window->driverdata = NULL;
if (data) { if (data) {
SDL_VideoData *videodata = (SDL_VideoData *) data->videodata; SDL_VideoData *videodata = (SDL_VideoData *) data->videodata;
Display *display = videodata->display; Display *display = videodata->display;
@ -1424,6 +1422,7 @@ X11_DestroyWindow(_THIS, SDL_Window * window)
} }
SDL_free(data); SDL_free(data);
} }
window->driverdata = NULL;
} }
SDL_bool SDL_bool