From 2df599ee5f8b0a98cca4ec24e6ac284d722673e2 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Mon, 31 May 2021 21:51:12 -0400
Subject: [PATCH] Made macOS error_dialog actually work.
Fixes #47.
---
src/SDL12_compat_objc.m | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/SDL12_compat_objc.m b/src/SDL12_compat_objc.m
index 2d9346c..a00e0b4 100644
--- a/src/SDL12_compat_objc.m
+++ b/src/SDL12_compat_objc.m
@@ -45,8 +45,20 @@ SDL12_PRIVATE void sdl12_compat_macos_init(void)
SDL12_PRIVATE void error_dialog(const char *errorMsg)
{
- NSString* msg = [NSString stringWithCString:errorMsg encoding:NSASCIIStringEncoding];
- NSRunCriticalAlertPanel (@"Error", @"%@", @"OK", nil, nil, msg);
+ if (NSApp == nil) {
+ ProcessSerialNumber psn = { 0, kCurrentProcess };
+ TransformProcessType(&psn, kProcessTransformToForegroundApplication);
+ [NSApplication sharedApplication];
+ [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
+ [NSApp finishLaunching];
+ }
+
+ [NSApp activateIgnoringOtherApps:YES];
+ NSAlert *alert = [[[NSAlert alloc] init] autorelease];
+ alert.alertStyle = NSAlertStyleCritical;
+ alert.messageText = @"Fatal error! Cannot continue!";
+ alert.informativeText = [NSString stringWithCString:errorMsg encoding:NSASCIIStringEncoding];
+ [alert runModal];
}
#endif