From 1faf6c87c38c22bea52965fdb697514ddde8d78d Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Tue, 9 Jun 2020 18:54:32 -0700 Subject: [PATCH] Reimplement log_displayBox on macOS. NSRunCriticalAlertPanel was replaced with the NSAlert class in 10.3 and deprecated in 10.10. This rewrite uses that class instead. Furthermore, original comments to the contrary, we are not compiling with ARC and need to actually release the classes we create and allow for an autorelease pool. --- sc2/src/libs/log/msgbox_macosx.m | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/sc2/src/libs/log/msgbox_macosx.m b/sc2/src/libs/log/msgbox_macosx.m index cb4adc696..eca32be6d 100644 --- a/sc2/src/libs/log/msgbox_macosx.m +++ b/sc2/src/libs/log/msgbox_macosx.m @@ -21,17 +21,22 @@ void log_displayBox (const /*UTF-8*/char *title, int isError, const /*UTF-8*/char *msg) { - NSString *titleStr = [NSString stringWithUTF8String:title]; - NSString *msgStr = [NSString stringWithUTF8String:msg]; + @autoreleasepool { + NSAlert *alert = [[NSAlert alloc] init]; + NSString *titleStr = [NSString stringWithUTF8String:title]; + NSString *msgStr = [NSString stringWithUTF8String:msg]; - if (!titleStr || !msgStr) - return; // Oops, out of memory? + if (alert && titleStr && msgStr) { + alert.alertStyle = isError ? NSAlertStyleCritical : NSAlertStyleInformational; + alert.messageText = titleStr; + alert.informativeText = msgStr; - if (isError) - NSRunCriticalAlertPanel (titleStr, @"%@", nil, nil, nil, msgStr); - else - NSRunInformationalAlertPanel (titleStr, @"%@", nil, nil, nil, msgStr); + [alert runModal]; + } - // titleStr and msgStr are autoreleased + [msgStr release]; + [titleStr release]; + [alert release]; + } }