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.
This commit is contained in:
U-DESKTOP-SPFP6AQ\twistedtechre committed 2026-04-21 02:49:49 +02:00
1 parent d69251dd98
commit aa5c9261a7
1 file changed
+7 -1
+7 -1
View File
@@ -1328,7 +1328,13 @@ static NSMenu *cocoa_create_help_menu(void)
NSMenu *menu = [[NSMenu alloc] initWithTitle:@"Help"];
[menu addItem:cocoa_menu_item_with_action(@"RetroArch Help",
@selector(showHelp:), @"?", NSEventModifierFlagCommand, nil, 0)];
[NSApp setHelpMenu:menu];
/* -[NSApplication setHelpMenu:] is 10.6+. Runtime-guard so we
* don't crash with "unrecognized selector" on 10.5 Leopard. The
* help menu still appears in the menu bar via setMainMenu; this
* call is only about telling AppKit which one to route Spotlight-
* for-Help into. */
if ([NSApp respondsToSelector:@selector(setHelpMenu:)])
[NSApp setHelpMenu:menu];
#ifndef HAVE_COCOA_METAL
[menu autorelease];
#endif