mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 03:25:14 -04:00
macOS: Try to prevent errors when showing a dialog from crashing the game
Also try to use descriptive error names in crash message box on Windows
This commit is contained in:
parent
1a7ed4e60f
commit
9f951893a1
17
src/Logger.c
17
src/Logger.c
@ -950,17 +950,32 @@ static void DumpMisc(void* ctx) { }
|
||||
*--------------------------------------------------Unhandled error logging------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#if defined CC_BUILD_WIN
|
||||
static const char* ExceptionDescribe(cc_uint32 code) {
|
||||
switch (code) {
|
||||
case EXCEPTION_ACCESS_VIOLATION: return "ACCESS_VIOLATION";
|
||||
case EXCEPTION_ILLEGAL_INSTRUCTION: return "ILLEGAL_INSTRUCTION";
|
||||
case EXCEPTION_INT_DIVIDE_BY_ZERO: return "DIVIDE_BY_ZERO";
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static LONG WINAPI UnhandledFilter(struct _EXCEPTION_POINTERS* info) {
|
||||
cc_string msg; char msgBuffer[128 + 1];
|
||||
const char* desc;
|
||||
cc_uint32 code;
|
||||
cc_uintptr addr;
|
||||
DWORD i, numArgs;
|
||||
|
||||
code = (cc_uint32)info->ExceptionRecord->ExceptionCode;
|
||||
addr = (cc_uintptr)info->ExceptionRecord->ExceptionAddress;
|
||||
desc = ExceptionDescribe(code);
|
||||
|
||||
String_InitArray_NT(msg, msgBuffer);
|
||||
String_Format2(&msg, "Unhandled exception 0x%h at %x", &code, &addr);
|
||||
if (desc) {
|
||||
String_Format2(&msg, "Unhandled %c error at %x", desc, &addr);
|
||||
} else {
|
||||
String_Format2(&msg, "Unhandled exception 0x%h at %x", &code, &addr);
|
||||
}
|
||||
|
||||
numArgs = info->ExceptionRecord->NumberParameters;
|
||||
if (numArgs) {
|
||||
|
@ -156,6 +156,9 @@ void Window_Init(void) {
|
||||
appHandle = [NSApplication sharedApplication];
|
||||
[appHandle activateIgnoringOtherApps:YES];
|
||||
Window_CommonInit();
|
||||
|
||||
// NSApplication sometimes replaces the uncaught exception handler, so set it again
|
||||
NSSetUncaughtExceptionHandler(LogUnhandledNSErrors);
|
||||
}
|
||||
|
||||
|
||||
@ -540,11 +543,17 @@ void ShowDialogCore(const char* title, const char* msg) {
|
||||
CFStringRef titleCF, msgCF;
|
||||
NSAlert* alert;
|
||||
|
||||
alert = [NSAlert alloc];
|
||||
alert = [alert init];
|
||||
titleCF = CFStringCreateWithCString(NULL, title, kCFStringEncodingASCII);
|
||||
msgCF = CFStringCreateWithCString(NULL, msg, kCFStringEncodingASCII);
|
||||
|
||||
// backwards compatible @try @catch
|
||||
NS_DURING {
|
||||
alert = [NSAlert alloc];
|
||||
alert = [alert init];
|
||||
} NS_HANDLER {
|
||||
LogUnhandledNSErrors(localException);
|
||||
} NS_ENDHANDLER
|
||||
|
||||
[alert setMessageText: titleCF];
|
||||
[alert setInformativeText: msgCF];
|
||||
[alert addButtonWithTitle: @"OK"];
|
||||
|
Loading…
x
Reference in New Issue
Block a user