We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2629

Summary: [Patch] Mac: crash when calling SDL_DestroyWindow with an active OpenGL context
Product: SDL Reporter: Alex Szpakowski <amaranth72>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: HG 2.0   
Hardware: x86_64   
OS: Mac OS X (All)   
Attachments: Patch to fix SDL_DestroyWindow crashing

Description Alex Szpakowski 2014-07-06 01:49:23 UTC
Created attachment 1736 [details]
Patch to fix SDL_DestroyWindow crashing

Since this commit https://hg.libsdl.org/SDL/rev/1519c462cee6 , 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.
Comment 1 Sam Lantinga 2014-07-07 17:33:57 UTC
Nice catch, thanks!
https://hg.libsdl.org/SDL/rev/7753e4fd3d1d