Commit 218c3dbb348e042e02072f950915662a6f345e94

Ryan C. Gordon 2022-07-26T14:45:26

cocoa: Don't crash if moving a message box created before SDL_Init. Fixes #5928.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m
index fcee0a7..da5ffac 100644
--- a/src/video/cocoa/SDL_cocoamouse.m
+++ b/src/video/cocoa/SDL_cocoamouse.m
@@ -400,6 +400,12 @@ Cocoa_HandleTitleButtonEvent(_THIS, NSEvent *event)
     SDL_Window *window;
     NSWindow *nswindow = [event window];
 
+    /* You might land in this function before SDL_Init if showing a message box.
+       Don't derefence a NULL pointer if that happens. */
+    if (_this == NULL) {
+        return;
+    }
+
     for (window = _this->windows; window; window = window->next) {
         SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata;
         if (data && data.nswindow == nswindow) {