Skip to content

Commit aa5c926

Browse files
committed
ui_cocoa: runtime-guard setHelpMenu: for pre-10.6 Leopard
On 10.5 Leopard, the app crashes at menu-bar construction: NSApplication setHelpMenu:]: unrecognized selector sent to instance 0x6311b50 An uncaught exception was raised -[NSApplication setHelpMenu:] is annotated NS_AVAILABLE_MAC(10_6) and was added in Snow Leopard. On 10.5 the selector doesn't exist in AppKit, so the Obj-C runtime throws NSInvalidArgumentException. This is a runtime issue, not a compile issue - the code builds cleanly against the 10.5 SDK because the selector is just a name the runtime resolves at dispatch time. Can't use @available (clang-only, Xcode 7+), so use the pre-Obj-C-2.0 idiom: if ([NSApp respondsToSelector:@selector(setHelpMenu:)]) [NSApp setHelpMenu:menu]; Works on every Obj-C compiler back to 1.0, zero overhead on modern builds. The other NSApplication menu-setters in this file (setMainMenu:, setServicesMenu:, setWindowsMenu:) are all 10.0-era and need no guard. Only setHelpMenu: is the 10.6 addition. What Leopard loses: setHelpMenu: tells AppKit which menu to inject Spotlight-for-Help into. The Help menu itself still appears via setMainMenu: in cocoa_create_menu_bar(). Spotlight-for-Help was also a 10.6 addition, so there's nothing to inject on Leopard anyway. No regression for modern macOS.
1 parent d69251d commit aa5c926

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

ui/drivers/ui_cocoa.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,13 @@ - (void)alertDidEnd:(NSAlert *)alert returnCode:(int32_t)returnCode contextInfo:
13281328
NSMenu *menu = [[NSMenu alloc] initWithTitle:@"Help"];
13291329
[menu addItem:cocoa_menu_item_with_action(@"RetroArch Help",
13301330
@selector(showHelp:), @"?", NSEventModifierFlagCommand, nil, 0)];
1331-
[NSApp setHelpMenu:menu];
1331+
/* -[NSApplication setHelpMenu:] is 10.6+. Runtime-guard so we
1332+
* don't crash with "unrecognized selector" on 10.5 Leopard. The
1333+
* help menu still appears in the menu bar via setMainMenu; this
1334+
* call is only about telling AppKit which one to route Spotlight-
1335+
* for-Help into. */
1336+
if ([NSApp respondsToSelector:@selector(setHelpMenu:)])
1337+
[NSApp setHelpMenu:menu];
13321338
#ifndef HAVE_COCOA_METAL
13331339
[menu autorelease];
13341340
#endif

0 commit comments

Comments
 (0)