SDL: cocoa: Return an error if GetWindowDisplayIndex() is called too early

From 3046d55d0e9058d47df1abf41fea1e51c1cd7fd5 Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Fri, 12 Aug 2022 22:02:26 -0500
Subject: [PATCH] cocoa: Return an error if GetWindowDisplayIndex() is called
 too early

SDL_CreateWindow() may call GetWindowDisplayIndex() to compute the position
of a new window that the caller has requested to be placed on a certain
display. Since we haven't fully constructed the window yet, our driverdata
will be nil and we will fail to get the NSScreen (which is fine). However,
we need to return an error (not 0, which is a valid display index) for
SDL_GetWindowDisplayIndex() to know to figure out the display index itself.

Fixes positioning new windows on secondary displays when using
SDL_WINDOWPOS_CENTERED_DISPLAY() and SDL_WINDOWPOS_UNDEFINED_DISPLAY().
---
 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 63a8b7659e6..ad56e7b94aa 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -2228,7 +2228,7 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
 
     /* Not recognized via CHECK_WINDOW_MAGIC */
     if (data == nil) {
-        return 0;
+        return SDL_SetError("Window data not set");
     }
 
     /* NSWindow.screen may be nil when the window is off-screen. */