From 630258982957579fb31f85ea831f09aa281d7eda Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 18 Mar 2025 14:36:48 -0700
Subject: [PATCH] Use an autoreleasepool in Cocoa_GetDisplayUsableBounds()
Fixes https://github.com/libsdl-org/SDL/issues/12571
(cherry picked from commit 8b924df48b17eef05834cb14129e52afb1075f46)
---
src/video/cocoa/SDL_cocoamodes.m | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m
index b3c34ba08d704..4c168de8d356e 100644
--- a/src/video/cocoa/SDL_cocoamodes.m
+++ b/src/video/cocoa/SDL_cocoamodes.m
@@ -556,22 +556,24 @@ bool Cocoa_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, S
bool Cocoa_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
{
- SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal;
- NSScreen *screen = GetNSScreenForDisplayID(displaydata->display);
+ @autoreleasepool {
+ SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal;
+ NSScreen *screen = GetNSScreenForDisplayID(displaydata->display);
- if (screen == nil) {
- return SDL_SetError("Couldn't get NSScreen for display");
- }
+ if (screen == nil) {
+ return SDL_SetError("Couldn't get NSScreen for display");
+ }
- {
- const NSRect frame = [screen visibleFrame];
- rect->x = (int)frame.origin.x;
- rect->y = (int)(CGDisplayPixelsHigh(kCGDirectMainDisplay) - frame.origin.y - frame.size.height);
- rect->w = (int)frame.size.width;
- rect->h = (int)frame.size.height;
- }
+ {
+ const NSRect frame = [screen visibleFrame];
+ rect->x = (int)frame.origin.x;
+ rect->y = (int)(CGDisplayPixelsHigh(kCGDirectMainDisplay) - frame.origin.y - frame.size.height);
+ rect->w = (int)frame.size.width;
+ rect->h = (int)frame.size.height;
+ }
- return true;
+ return true;
+ }
}
bool Cocoa_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)