Skip to content

Commit 3030b78

Browse files
committed
cocoa_gl_ctx: runtime-guard setColorSpace: for pre-10.6 Leopard
On 10.5 Leopard, RetroArch crashes during GL context creation: [NSWindow setColorSpace:]: unrecognized selector sent to instance 0x631bad0 -[NSWindow setColorSpace:] is annotated NS_AVAILABLE_MAC(10_6). Snow Leopard introduced color-space-aware window tagging; 10.5's NSWindow doesn't have the selector. Same class of runtime issue as aa5c926 (setHelpMenu:) and the URLForResource: guard: compile succeeds because messages to id dispatch dynamically, but the Obj-C runtime can't resolve the selector at dispatch time and throws NSInvalidArgumentException. Runtime-guard with respondsToSelector:: NSWindow *win = [g_view window]; if ([win respondsToSelector:@selector(setColorSpace:)]) [win setColorSpace:[NSColorSpace sRGBColorSpace]]; Wrapped in a block so the local NSWindow* doesn't leak into the surrounding scope. +[NSColorSpace sRGBColorSpace] on the same line is 10.5+ (NS_AVAILABLE_MAC(10_5) per the header) so it stays unguarded. Only the NSWindow selector is the 10.6 addition. Behavioral impact on Leopard: windows use the system default color space, which is what Leopard always did anyway - color-space-aware window tagging didn't exist pre-10.6. Modern macOS still gets the explicit sRGB tag as before.
1 parent db35429 commit 3030b78

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

gfx/drivers_context/cocoa_gl_ctx.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,17 @@ static bool cocoa_gl_gfx_ctx_set_video_mode(void *data,
438438
}
439439

440440
[g_ctx setView:g_view];
441-
[[g_view window] setColorSpace:[NSColorSpace sRGBColorSpace]];
441+
{
442+
/* -[NSWindow setColorSpace:] is NS_AVAILABLE_MAC(10_6). On 10.5
443+
* Leopard the selector doesn't exist and the runtime throws
444+
* "unrecognized selector". Without this call the window simply
445+
* uses the default colour space (which is what 10.5 always did
446+
* anyway), so skip it on systems that lack the method.
447+
* +[NSColorSpace sRGBColorSpace] itself is 10.5+ and is safe. */
448+
NSWindow *win = [g_view window];
449+
if ([win respondsToSelector:@selector(setColorSpace:)])
450+
[win setColorSpace:[NSColorSpace sRGBColorSpace]];
451+
}
442452
#ifdef OSX
443453
[g_ctx makeCurrentContext];
444454
#else

0 commit comments

Comments
 (0)