SDL: cocoa: Set the internal window data before calling methods that may result in referencing the internal data (a530d)

From a530df20b25c0ecb7999c4cb4984e37a1d0c4359 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Wed, 12 Mar 2025 15:36:56 -0400
Subject: [PATCH] cocoa: Set the internal window data before calling methods
 that may result in referencing the internal data

(cherry picked from commit 512d97eabaec3f16ffc59f486d03711861618d46)
---
 src/video/cocoa/SDL_cocoawindow.m | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 52943e8f567f6..a81791ca98772 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -2126,6 +2126,7 @@ static bool SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow
         if (!data) {
             return SDL_OutOfMemory();
         }
+        window->internal = (SDL_WindowData *)CFBridgingRetain(data);
         data.window = window;
         data.nswindow = nswindow;
         data.videodata = videodata;
@@ -2246,7 +2247,6 @@ then immediately ordering out (removing) the window does work. */
         SDL_SetNumberProperty(props, SDL_PROP_WINDOW_COCOA_METAL_VIEW_TAG_NUMBER, SDL_METALVIEW_TAG);
 
         // All done!
-        window->internal = (SDL_WindowData *)CFBridgingRetain(data);
         return true;
     }
 }