Skip to content

Commit db35429

Browse files
committed
platform_darwin: runtime-guard URLForResource: for pre-10.6 Leopard
On 10.5 Leopard, RetroArch crashes at startup during default-dir setup: [NSBundle URLForResource:withExtension:subdirectory:]: unrecognized selector sent to instance 0x632d410 -[NSBundle URLForResource:withExtension:subdirectory:] is annotated NS_AVAILABLE(10_6, 4_0) in the 10.8 SDK header - added in Snow Leopard as part of NSBundle's URL-based API. 10.5 NSBundle only has the older pathForResource:-style methods returning NSString *. Same class of issue as setHelpMenu: (aa5c926): compile succeeds because messages to id dispatch dynamically, but the runtime can't resolve the selector and throws NSInvalidArgumentException. Use the same pre-Obj-C-2.0 idiom: if ([[NSBundle mainBundle] respondsToSelector: @selector(URLForResource:withExtension:subdirectory:)]) url = [[NSBundle mainBundle] URLForResource:...]; Both callers in this file (DEFAULT_DIR_AUDIO_FILTER and DEFAULT_DIR_VIDEO_FILTER setup) already have a fill_pathname_join fallback for the url==nil case, so the guard just needs to keep url nil on 10.5. Cache the SEL in a local since both calls use the same selector. Behavioral impact on Leopard: no bundle-shipped filter auto- discovery; audio/video filter dirs always resolve to application_data/filters/{audio,video} via the existing fallback. That's RetroArch's conventional path anyway - the URLForResource: trick is only an optimization for bundles that ship filters inline, which is rare on desktop macOS. Modern macOS behavior unchanged. Other NSBundle methods in this file (objectForInfoDictionaryKey: at lines 392, 491) are 10.0-era and need no guard.
1 parent aa5c926 commit db35429

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

frontend/drivers/platform_darwin.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,23 @@ static void frontend_darwin_get_env(int *argc, char *argv[],
444444
#endif
445445
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_DATABASE], application_data, "database/rdb", sizeof(g_defaults.dirs[DEFAULT_DIR_DATABASE]));
446446
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_ASSETS], application_data, "downloads", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE_ASSETS]));
447-
NSURL *url = [[NSBundle mainBundle] URLForResource:nil withExtension:@"dsp" subdirectory:@"filters/audio"];
447+
/* -[NSBundle URLForResource:withExtension:subdirectory:] is 10.6+
448+
* (NS_AVAILABLE(10_6, 4_0)). On 10.5 Leopard the selector doesn't
449+
* exist and the runtime throws "unrecognized selector". Guard
450+
* with respondsToSelector: and fall through to the existing
451+
* fill_pathname_join fallback on older systems, which simply
452+
* won't do bundle-shipped filter auto-discovery. */
453+
NSURL *url = nil;
454+
SEL url_for_resource_sel = @selector(URLForResource:withExtension:subdirectory:);
455+
if ([[NSBundle mainBundle] respondsToSelector:url_for_resource_sel])
456+
url = [[NSBundle mainBundle] URLForResource:nil withExtension:@"dsp" subdirectory:@"filters/audio"];
448457
if (url)
449458
strlcpy(g_defaults.dirs[DEFAULT_DIR_AUDIO_FILTER], [[url baseURL] fileSystemRepresentation], sizeof(g_defaults.dirs[DEFAULT_DIR_AUDIO_FILTER]));
450459
else
451460
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_AUDIO_FILTER], application_data, "filters/audio", sizeof(g_defaults.dirs[DEFAULT_DIR_AUDIO_FILTER]));
452-
url = [[NSBundle mainBundle] URLForResource:nil withExtension:@"filt" subdirectory:@"filters/video"];
461+
url = nil;
462+
if ([[NSBundle mainBundle] respondsToSelector:url_for_resource_sel])
463+
url = [[NSBundle mainBundle] URLForResource:nil withExtension:@"filt" subdirectory:@"filters/video"];
453464
if (url)
454465
strlcpy(g_defaults.dirs[DEFAULT_DIR_VIDEO_FILTER], [[url baseURL] fileSystemRepresentation], sizeof(g_defaults.dirs[DEFAULT_DIR_VIDEO_FILTER]));
455466
else

0 commit comments

Comments
 (0)