Gracefully handle lack of bundle on macOS

should fix https://github.com/minetest/minetest/issues/10170
This commit is contained in:
sfan5 2022-01-31 20:48:00 +01:00
parent 7d1dc8b2d5
commit fa2a7dc236

@ -553,7 +553,6 @@ CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
IsActive(true), IsFullscreen(false), IsShiftDown(false), IsControlDown(false), IsResizable(false) IsActive(true), IsFullscreen(false), IsShiftDown(false), IsControlDown(false), IsResizable(false)
{ {
struct utsname name; struct utsname name;
NSString *path;
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CIrrDeviceMacOSX"); setDebugName("CIrrDeviceMacOSX");
@ -568,27 +567,31 @@ CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
[[NSAutoreleasePool alloc] init]; [[NSAutoreleasePool alloc] init];
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
[NSApp setDelegate:(id<NSApplicationDelegate>)[[[CIrrDelegateOSX alloc] initWithDevice:this] autorelease]]; [NSApp setDelegate:(id<NSApplicationDelegate>)[[[CIrrDelegateOSX alloc] initWithDevice:this] autorelease]];
// Create menu // Create menu
NSString* bundleName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; NSString* bundleName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
if (bundleName == nil)
bundleName = @"Irrlicht";
NSMenu* mainMenu = [[[NSMenu alloc] initWithTitle:@"MainMenu"] autorelease]; NSMenu* mainMenu = [[[NSMenu alloc] initWithTitle:@"MainMenu"] autorelease];
NSMenu* menu = [[[NSMenu alloc] initWithTitle:bundleName] autorelease]; NSMenu* menu = [[[NSMenu alloc] initWithTitle:bundleName] autorelease];
NSMenuItem* menuItem = [mainMenu addItemWithTitle:bundleName action:nil keyEquivalent:@""]; NSMenuItem* menuItem = [mainMenu addItemWithTitle:bundleName action:nil keyEquivalent:@""];
[mainMenu setSubmenu:menu forItem:menuItem]; [mainMenu setSubmenu:menu forItem:menuItem];
menuItem = [menu addItemWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"]; menuItem = [menu addItemWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"];
[menuItem setKeyEquivalentModifierMask:NSCommandKeyMask]; [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];
[NSApp setMainMenu:mainMenu]; [NSApp setMainMenu:mainMenu];
[NSApp finishLaunching]; [NSApp finishLaunching];
} }
path = [[NSBundle mainBundle] bundlePath]; NSString *path = [[NSBundle mainBundle] bundlePath];
path = [path stringByAppendingString:@"/Contents/Resources"]; if (path != nil) {
chdir([path fileSystemRepresentation]); path = [path stringByAppendingString:@"/Contents/Resources"];
[path release]; chdir([path fileSystemRepresentation]);
[path release];
}
} }
uname(&name); uname(&name);