From 5c5ba0e3317c07b309a80d62fbe3b78b5d8534b1 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 19 Nov 2018 21:35:59 -0800 Subject: [PATCH] Fixed bug 4394 - Crash in SDL_PumpEvents() after SDL_DestroyWindow() Cameron Gutman After updating to SDL 2.0.9, I got a user report that my app was crashing when closing a SDL_WINDOW_FULLSCREEN window to return to my Qt-based UI. It looks like the dead SDL window is getting a spurious updateLayer call which is causing SDL to dereference a null SDL_WindowData pointer. For some reason, this only happens when using SDL_WINDOW_FULLSCREEN and not windowed or SDL_WINDOW_FULLSCREEN_DESKTOP. I was also unsuccessful in my attempt to get a simple reproducer for this crash. The Session.cpp code is available https://github.com/moonlight-stream/moonlight-qt/blob/688c4a90d994aa23e7b0af3ffcbb8707886db780/app/streaming/session.cpp but I slightly modified it (adding a SDL_PumpEvents() call at 1179 to immediately trigger the issue, otherwise it happened when Qt next pumped the event loop). The crashing line is: NSMutableArray *contexts = data->nscontexts; --- src/video/cocoa/SDL_cocoawindow.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 4503ae5c315ed..a3b056d342eeb 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -224,6 +224,10 @@ static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r) static void ScheduleContextUpdates(SDL_WindowData *data) { + if (!data || !data->nscontexts) { + return; + } + NSOpenGLContext *currentContext = [NSOpenGLContext currentContext]; NSMutableArray *contexts = data->nscontexts; @synchronized (contexts) {