From 94eea01df700b05acbba886b4aee8bbfd8e83350 Mon Sep 17 00:00:00 2001 From: emiyl Date: Fri, 24 Jul 2026 23:35:18 +0100 Subject: [PATCH 01/16] feat(vm): add show_error function --- src/vm_builtins.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/vm_builtins.c b/src/vm_builtins.c index e0ce4918e..cab9fc755 100644 --- a/src/vm_builtins.c +++ b/src/vm_builtins.c @@ -1821,6 +1821,28 @@ static RValue builtin_show_debug_message(MAYBE_UNUSED VMContext* ctx, RValue* ar return RValue_makeUndefined(); } +// show_error(str, abort) - Displays an error message and optionally aborts the game +static RValue builtin_show_error(MAYBE_UNUSED VMContext* ctx, RValue* args, int32_t argCount) { + if (1 > argCount) { + fprintf(stderr, "[show_error] Expected at least 1 argument\n"); + return RValue_makeUndefined(); + } + + char* val = RValue_toString(args[0]); + bool abort = false; + if (2 <= argCount) abort = RValue_toBool(args[1]); + + fprintf(stderr, "Game error: %s\n", val); + free(val); + + if (abort) { + fprintf(stderr, "Game aborted due to show_error() call.\n"); + exit(EXIT_FAILURE); + } + + return RValue_makeUndefined(); +} + static RValue builtin_string_length(MAYBE_UNUSED VMContext* ctx, RValue* args, int32_t argCount) { if (1 > argCount) return RValue_makeInt32(0); // GML converts non-string arguments to string before measuring length @@ -16368,6 +16390,7 @@ void VMBuiltins_registerAll(VMContext* ctx) { // Core output VM_registerBuiltin(ctx, "show_debug_message", builtin_show_debug_message); + VM_registerBuiltin(ctx, "show_error", builtin_show_error); // String functions VM_registerBuiltin(ctx, "string_length", builtin_string_length); From debcb4778ade3398cb16e9b4bde52118b75a9d20 Mon Sep 17 00:00:00 2001 From: emiyl Date: Sat, 25 Jul 2026 00:02:35 +0100 Subject: [PATCH 02/16] add error popups for desktop frontend --- CMakeLists.txt | 6 ++++++ src/desktop/backends/glfw2.c | 12 ++++++++++++ src/desktop/backends/glfw3.c | 12 ++++++++++++ src/desktop/backends/platform/macos.m | 18 ++++++++++++++++++ src/desktop/backends/sdl1.c | 17 +++++++++++++++++ src/desktop/backends/sdl2.c | 9 +++++++++ src/desktop/backends/sdl3.c | 9 +++++++++ src/desktop/main.c | 1 + src/desktop/platformdefs.h | 1 + src/runner.h | 1 + src/vm_builtins.c | 6 +++++- 11 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/desktop/backends/platform/macos.m diff --git a/CMakeLists.txt b/CMakeLists.txt index 924d470fa..5ee71082d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -186,6 +186,12 @@ if(PLATFORM STREQUAL "desktop") # Matches the GitHub Actions container flags (FORTIFY requires building with optimizations enabled!) target_compile_options(butterscotch PRIVATE "$<$:-U_FORTIFY_SOURCE;-D_FORTIFY_SOURCE=2>") + if(APPLE) + target_sources(butterscotch PRIVATE src/desktop/backends/platform/macos.m) + find_library(COCOA_LIBRARY Cocoa REQUIRED) + target_link_libraries(butterscotch PRIVATE ${COCOA_LIBRARY}) + endif() + if(NOT ENABLE_LEGACY_GL AND NOT ENABLE_MODERN_GL) message(FATAL_ERROR "You must enable at least one renderer!") endif() diff --git a/src/desktop/backends/glfw2.c b/src/desktop/backends/glfw2.c index e167674f3..f80f5a32e 100644 --- a/src/desktop/backends/glfw2.c +++ b/src/desktop/backends/glfw2.c @@ -56,6 +56,18 @@ static bool tryOpenWindow(int reqW, int reqH) { #endif } +#ifdef TARGET_OS_MAC +void show_error_box(const char *message); +#endif + +void platformShowErrorDialogue(const char* message) { +#ifdef _WIN32 + MessageBoxA(NULL, message, "Error", MB_OK | MB_ICONERROR); +#elif defined(TARGET_OS_MAC) + show_error_box(message); +#endif +} + void platformSetWindowTitle(const char* title) { char windowTitle[256]; snprintf(windowTitle, sizeof(windowTitle), "Butterscotch - %s", title); diff --git a/src/desktop/backends/glfw3.c b/src/desktop/backends/glfw3.c index 6d85924d8..3c62583de 100644 --- a/src/desktop/backends/glfw3.c +++ b/src/desktop/backends/glfw3.c @@ -79,6 +79,18 @@ static GLFWwindow *tryOpenWindow(int reqW, int reqH, const char* title) { return NULL; } +#ifdef TARGET_OS_MAC +void show_error_box(const char *message); +#endif + +void platformShowErrorDialogue(const char* message) { +#ifdef _WIN32 + MessageBoxA(NULL, message, "Error", MB_OK | MB_ICONERROR); +#elif defined(TARGET_OS_MAC) + show_error_box(message); +#endif +} + void platformSetWindowTitle(const char* title) { char windowTitle[256]; snprintf(windowTitle, sizeof(windowTitle), "Butterscotch - %s", title); diff --git a/src/desktop/backends/platform/macos.m b/src/desktop/backends/platform/macos.m new file mode 100644 index 000000000..d23f7574a --- /dev/null +++ b/src/desktop/backends/platform/macos.m @@ -0,0 +1,18 @@ +#import + +void show_error_box(const char *message) +{ + printf("Error: %s\n", message); + @autoreleasepool { + NSAlert *alert = [[NSAlert alloc] init]; + + [alert setMessageText:@"Error"]; + [alert setInformativeText: + [NSString stringWithUTF8String:message]]; + + [alert addButtonWithTitle:@"OK"]; + [alert setAlertStyle:NSAlertStyleCritical]; + + [alert runModal]; + } +} \ No newline at end of file diff --git a/src/desktop/backends/sdl1.c b/src/desktop/backends/sdl1.c index 766cc0c8d..fa927184e 100644 --- a/src/desktop/backends/sdl1.c +++ b/src/desktop/backends/sdl1.c @@ -4,6 +4,10 @@ #include #include +#ifdef _WIN32 +#include +#endif + #include #include "common.h" @@ -201,6 +205,19 @@ static void loadGamepadMappings(void) { } fclose(f); } + +#ifdef TARGET_OS_MAC +void show_error_box(const char *message); +#endif + +void platformShowErrorDialogue(const char* message) { +#ifdef _WIN32 + MessageBoxA(NULL, message, "Error", MB_OK | MB_ICONERROR); +#elif defined(TARGET_OS_MAC) + show_error_box(message); +#endif +} + void platformSetWindowTitle(const char* title) { char windowTitle[256]; snprintf(windowTitle, sizeof(windowTitle), "Butterscotch - %s", title); diff --git a/src/desktop/backends/sdl2.c b/src/desktop/backends/sdl2.c index ca4ca9828..708f63f2c 100644 --- a/src/desktop/backends/sdl2.c +++ b/src/desktop/backends/sdl2.c @@ -91,6 +91,15 @@ static SDL_Window *tryOpenWindow(int reqW, int reqH, const char* title, Uint32 f return NULL; } +void platformShowErrorDialogue(const char* message) { + SDL_ShowSimpleMessageBox( + SDL_MESSAGEBOX_ERROR, + "Error", + message, + NULL + ); +} + void platformSetWindowTitle(const char* title) { char windowTitle[256]; snprintf(windowTitle, sizeof(windowTitle), "Butterscotch - %s", title); diff --git a/src/desktop/backends/sdl3.c b/src/desktop/backends/sdl3.c index e1895790f..a00046356 100644 --- a/src/desktop/backends/sdl3.c +++ b/src/desktop/backends/sdl3.c @@ -108,6 +108,15 @@ static SDL_Window *tryOpenWindow(int reqW, int reqH, const char* title, Uint32 f return NULL; } +void platformShowErrorDialogue(const char* message) { + SDL_ShowSimpleMessageBox( + SDL_MESSAGEBOX_ERROR, + "Error", + message, + NULL + ); +} + void platformSetWindowTitle(const char* title) { char windowTitle[256]; snprintf(windowTitle, sizeof(windowTitle), "Butterscotch - %s", title); diff --git a/src/desktop/main.c b/src/desktop/main.c index 90635ae8d..c0b3ad6c8 100644 --- a/src/desktop/main.c +++ b/src/desktop/main.c @@ -1420,6 +1420,7 @@ int main(int argc, char* argv[]) { runner->setWindowSize = platformSetWindowSize; runner->getWindowSize = platformGetWindowSize; runner->setWindowTitle = platformSetWindowTitle; + runner->showErrorDialogue = platformShowErrorDialogue; Runner_setGameArgs(runner, currentGameArgs, (int32_t) arrlen(currentGameArgs)); platformInitFunctions(runner); diff --git a/src/desktop/platformdefs.h b/src/desktop/platformdefs.h index ad93f4b81..3a1cb71f3 100644 --- a/src/desktop/platformdefs.h +++ b/src/desktop/platformdefs.h @@ -19,6 +19,7 @@ bool platformGetScaledWindowSize(int32_t* outW, int32_t* outH); void platformSetWindowSize(int32_t width, int32_t height); void platformSetWindowTitle(const char* title); void platformSleepUntil(uint64_t time); +void platformShowErrorDialogue(const char* message); enum GraphicsAPI { SOFTWARE, diff --git a/src/runner.h b/src/runner.h index 066a7cadb..74ed97922 100644 --- a/src/runner.h +++ b/src/runner.h @@ -505,6 +505,7 @@ struct Runner { void (*setWindowTitle)(const char* title); bool (*getWindowSize)(int32_t* outW, int32_t* outH); void (*setWindowSize)(int32_t width, int32_t height); + void (*showErrorDialogue)(const char* message); bool (*windowHasFocus)(void); void (*setCursor)(int32_t cursorType); int32_t currentCursor; // last value passed to window_set_cursor diff --git a/src/vm_builtins.c b/src/vm_builtins.c index cab9fc755..7683e2e67 100644 --- a/src/vm_builtins.c +++ b/src/vm_builtins.c @@ -1832,7 +1832,11 @@ static RValue builtin_show_error(MAYBE_UNUSED VMContext* ctx, RValue* args, int3 bool abort = false; if (2 <= argCount) abort = RValue_toBool(args[1]); - fprintf(stderr, "Game error: %s\n", val); + fprintf(stderr, "[show_error] %s\n", val); + Runner* runner = ctx->runner; + if (runner->showErrorDialogue) { + runner->showErrorDialogue(val); + } free(val); if (abort) { From bcb3adc104b579d1ac0cb63dc9b7aeb8c5592884 Mon Sep 17 00:00:00 2001 From: emiyl Date: Sat, 25 Jul 2026 00:06:41 +0100 Subject: [PATCH 03/16] supress unused parameter warning --- src/desktop/backends/glfw2.c | 2 ++ src/desktop/backends/glfw3.c | 2 ++ src/desktop/backends/sdl1.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/desktop/backends/glfw2.c b/src/desktop/backends/glfw2.c index f80f5a32e..1cdf9932d 100644 --- a/src/desktop/backends/glfw2.c +++ b/src/desktop/backends/glfw2.c @@ -65,6 +65,8 @@ void platformShowErrorDialogue(const char* message) { MessageBoxA(NULL, message, "Error", MB_OK | MB_ICONERROR); #elif defined(TARGET_OS_MAC) show_error_box(message); +#else + void(message); // Suppress unused parameter warning #endif } diff --git a/src/desktop/backends/glfw3.c b/src/desktop/backends/glfw3.c index 3c62583de..2bcacb943 100644 --- a/src/desktop/backends/glfw3.c +++ b/src/desktop/backends/glfw3.c @@ -88,6 +88,8 @@ void platformShowErrorDialogue(const char* message) { MessageBoxA(NULL, message, "Error", MB_OK | MB_ICONERROR); #elif defined(TARGET_OS_MAC) show_error_box(message); +#else + void(message); // Suppress unused parameter warning #endif } diff --git a/src/desktop/backends/sdl1.c b/src/desktop/backends/sdl1.c index fa927184e..ea76b89bd 100644 --- a/src/desktop/backends/sdl1.c +++ b/src/desktop/backends/sdl1.c @@ -215,6 +215,8 @@ void platformShowErrorDialogue(const char* message) { MessageBoxA(NULL, message, "Error", MB_OK | MB_ICONERROR); #elif defined(TARGET_OS_MAC) show_error_box(message); +#else + void(message); // Suppress unused parameter warning #endif } From 1bbba042e8215b3df33d4a5c4ae3cd6aa829c4f9 Mon Sep 17 00:00:00 2001 From: emiyl Date: Sat, 25 Jul 2026 00:09:16 +0100 Subject: [PATCH 04/16] how do brackets work again --- src/desktop/backends/glfw2.c | 2 +- src/desktop/backends/glfw3.c | 2 +- src/desktop/backends/sdl1.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/desktop/backends/glfw2.c b/src/desktop/backends/glfw2.c index 1cdf9932d..e8ac77e4e 100644 --- a/src/desktop/backends/glfw2.c +++ b/src/desktop/backends/glfw2.c @@ -66,7 +66,7 @@ void platformShowErrorDialogue(const char* message) { #elif defined(TARGET_OS_MAC) show_error_box(message); #else - void(message); // Suppress unused parameter warning + (void)message; // Suppress unused parameter warning #endif } diff --git a/src/desktop/backends/glfw3.c b/src/desktop/backends/glfw3.c index 2bcacb943..3c78ac595 100644 --- a/src/desktop/backends/glfw3.c +++ b/src/desktop/backends/glfw3.c @@ -89,7 +89,7 @@ void platformShowErrorDialogue(const char* message) { #elif defined(TARGET_OS_MAC) show_error_box(message); #else - void(message); // Suppress unused parameter warning + (void)message; // Suppress unused parameter warning #endif } diff --git a/src/desktop/backends/sdl1.c b/src/desktop/backends/sdl1.c index ea76b89bd..e72f51872 100644 --- a/src/desktop/backends/sdl1.c +++ b/src/desktop/backends/sdl1.c @@ -216,7 +216,7 @@ void platformShowErrorDialogue(const char* message) { #elif defined(TARGET_OS_MAC) show_error_box(message); #else - void(message); // Suppress unused parameter warning + (void)message; // Suppress unused parameter warning #endif } From 3fd4ca1fc1ba6a6d6613217a9b80559d8b3742f5 Mon Sep 17 00:00:00 2001 From: emiyl Date: Sat, 25 Jul 2026 00:14:25 +0100 Subject: [PATCH 05/16] specifically target darwin, and not just any apple system --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ee71082d..0a5c09143 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -186,7 +186,7 @@ if(PLATFORM STREQUAL "desktop") # Matches the GitHub Actions container flags (FORTIFY requires building with optimizations enabled!) target_compile_options(butterscotch PRIVATE "$<$:-U_FORTIFY_SOURCE;-D_FORTIFY_SOURCE=2>") - if(APPLE) + if(APPLE AND CMAKE_SYSTEM_NAME STREQUAL "Darwin") target_sources(butterscotch PRIVATE src/desktop/backends/platform/macos.m) find_library(COCOA_LIBRARY Cocoa REQUIRED) target_link_libraries(butterscotch PRIVATE ${COCOA_LIBRARY}) From 9c31449e6cd674e8ce51ec81aaa9432a976018aa Mon Sep 17 00:00:00 2001 From: emiyl Date: Sat, 25 Jul 2026 00:23:05 +0100 Subject: [PATCH 06/16] add macos stuff to makefile --- CMakeLists.txt | 2 +- Makefile | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a5c09143..3ff886aec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -186,7 +186,7 @@ if(PLATFORM STREQUAL "desktop") # Matches the GitHub Actions container flags (FORTIFY requires building with optimizations enabled!) target_compile_options(butterscotch PRIVATE "$<$:-U_FORTIFY_SOURCE;-D_FORTIFY_SOURCE=2>") - if(APPLE AND CMAKE_SYSTEM_NAME STREQUAL "Darwin") + if(APPLE AND NOT IOS) target_sources(butterscotch PRIVATE src/desktop/backends/platform/macos.m) find_library(COCOA_LIBRARY Cocoa REQUIRED) target_link_libraries(butterscotch PRIVATE ${COCOA_LIBRARY}) diff --git a/Makefile b/Makefile index 088238a50..9ba733105 100644 --- a/Makefile +++ b/Makefile @@ -80,17 +80,29 @@ GLFW3_LIBS += $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs glfw3) LIBS += $(GLFW3_LIBS) DEFINES += $(DEFINE)USE_GLFW3 ENABLE_GLAD := 1 +ifeq ($(OS),Darwin) +SRCS += src/desktop/backends/platform/macos.m +LIBS += -framework Cocoa +endif endif ifeq ($(DESKTOP_BACKEND),glfw2) GLFW2_LIBS += $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs libglfw) LIBS += $(GLFW2_LIBS) DEFINES += $(DEFINE)USE_GLFW2 ENABLE_GLAD := 1 +ifeq ($(OS),Darwin) +SRCS += src/desktop/backends/platform/macos.m +LIBS += -framework Cocoa +endif endif ifeq ($(DESKTOP_BACKEND),sdl1) SDL1_LIBS += $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs sdl) LIBS += $(SDL1_LIBS) DEFINES += $(DEFINE)USE_SDL1 +ifeq ($(OS),Darwin) +SRCS += src/desktop/backends/platform/macos.m +LIBS += -framework Cocoa +endif endif ifeq ($(DESKTOP_BACKEND),sdl2) SDL2_LIBS += $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs sdl2) From 73cd00afa7907e81e546d306a39483dbc356b87b Mon Sep 17 00:00:00 2001 From: emiyl Date: Sat, 25 Jul 2026 00:29:04 +0100 Subject: [PATCH 07/16] fix makefile for macos and add .m files --- Makefile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9ba733105..3ccb66829 100644 --- a/Makefile +++ b/Makefile @@ -76,7 +76,9 @@ PKG_CONFIG_FLAGS := --static endif INCLUDES += $(INCLUDE)src/desktop ifeq ($(DESKTOP_BACKEND),glfw3) -GLFW3_LIBS += $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs glfw3) +GLFW3_CFLAGS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --cflags glfw3) +GLFW3_LIBS := $(shell $(PKG_CONFIG) $(PKG_CONFIG_FLAGS) --libs glfw3) +CFLAGS += $(GLFW3_CFLAGS) LIBS += $(GLFW3_LIBS) DEFINES += $(DEFINE)USE_GLFW3 ENABLE_GLAD := 1 @@ -206,6 +208,7 @@ V := @ endif OBJS := $(addprefix build/,$(SRCS:.c=.c.$(OBJ_EXT))) +OBJS := $(OBJS:.m=.m.$(OBJ_EXT)) all: build/butterscotch @@ -228,6 +231,11 @@ build/%.c.$(OBJ_EXT): %.c compat/config.mk $(if $(DISABLE_MMD),$(HEADERS)) @{ [ -z "$(NO_COLOR)" ] && [ -t 1 ]; } && printf " \033[1;32mCC\033[0m $<\n" || printf " CC $<\n" $(V)MSYS2_ARG_CONV_EXCL='*' $(_CC) $(DEFINES) $(INCLUDES) $(CFLAGS) $(DEPFLAGS) $(COMPILE_OBJ) $(SRCFLAG)$< $(OUTPUT_OBJ)$@ +build/%.m.$(OBJ_EXT): %.m compat/config.mk $(if $(DISABLE_MMD),$(HEADERS)) + @mkdir -p $(dir $@) + @{ [ -z "$(NO_COLOR)" ] && [ -t 1 ]; } && printf " \033[1;32mOBJC\033[0m $<\n" || printf " OBJC $<\n" + $(V)MSYS2_ARG_CONV_EXCL='*' $(_CC) $(DEFINES) $(INCLUDES) $(CFLAGS) $(DEPFLAGS) $(COMPILE_OBJ) $< $(OUTPUT_OBJ)$@ + clean: rm -rf build From 8b1661d1899da31fc5129908c86bc6cb616ae92c Mon Sep 17 00:00:00 2001 From: emiyl Date: Sat, 25 Jul 2026 00:32:30 +0100 Subject: [PATCH 08/16] no duplicating compiler rule --- Makefile | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 3ccb66829..71ac80780 100644 --- a/Makefile +++ b/Makefile @@ -207,8 +207,8 @@ ifndef VERBOSE V := @ endif -OBJS := $(addprefix build/,$(SRCS:.c=.c.$(OBJ_EXT))) -OBJS := $(OBJS:.m=.m.$(OBJ_EXT)) +OBJS := $(addprefix build/,$(SRCS)) +OBJS := $(OBJS:%=%.$(OBJ_EXT)) all: build/butterscotch @@ -226,16 +226,11 @@ build/butterscotch: $(OBJS) $(V)MSYS2_ARG_CONV_EXCL='*' $(_CC) $(LDFLAGS) $(OBJS) $(LIBS) $(EXTRALIBS) $(OUTPUT_EXE)$@ @[ -f $@.exe ] && chmod +x $@.exe || true -build/%.c.$(OBJ_EXT): %.c compat/config.mk $(if $(DISABLE_MMD),$(HEADERS)) +build/%.$(OBJ_EXT): % compat/config.mk $(if $(DISABLE_MMD),$(HEADERS)) @mkdir -p $(dir $@) @{ [ -z "$(NO_COLOR)" ] && [ -t 1 ]; } && printf " \033[1;32mCC\033[0m $<\n" || printf " CC $<\n" $(V)MSYS2_ARG_CONV_EXCL='*' $(_CC) $(DEFINES) $(INCLUDES) $(CFLAGS) $(DEPFLAGS) $(COMPILE_OBJ) $(SRCFLAG)$< $(OUTPUT_OBJ)$@ -build/%.m.$(OBJ_EXT): %.m compat/config.mk $(if $(DISABLE_MMD),$(HEADERS)) - @mkdir -p $(dir $@) - @{ [ -z "$(NO_COLOR)" ] && [ -t 1 ]; } && printf " \033[1;32mOBJC\033[0m $<\n" || printf " OBJC $<\n" - $(V)MSYS2_ARG_CONV_EXCL='*' $(_CC) $(DEFINES) $(INCLUDES) $(CFLAGS) $(DEPFLAGS) $(COMPILE_OBJ) $< $(OUTPUT_OBJ)$@ - clean: rm -rf build From e1376e2c9dd8cee02538961534a16b2a2a3c56c6 Mon Sep 17 00:00:00 2001 From: emiyl Date: Sat, 25 Jul 2026 00:34:40 +0100 Subject: [PATCH 09/16] don't printf in the mac error box --- src/desktop/backends/platform/macos.m | 1 - 1 file changed, 1 deletion(-) diff --git a/src/desktop/backends/platform/macos.m b/src/desktop/backends/platform/macos.m index d23f7574a..abd4c32a5 100644 --- a/src/desktop/backends/platform/macos.m +++ b/src/desktop/backends/platform/macos.m @@ -2,7 +2,6 @@ void show_error_box(const char *message) { - printf("Error: %s\n", message); @autoreleasepool { NSAlert *alert = [[NSAlert alloc] init]; From a845acfaa823f71721107e911a342c1e65e611d5 Mon Sep 17 00:00:00 2001 From: emiyl Date: Sat, 25 Jul 2026 00:48:31 +0100 Subject: [PATCH 10/16] make the error message work on 10.3 and up --- src/desktop/backends/platform/macos.m | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/desktop/backends/platform/macos.m b/src/desktop/backends/platform/macos.m index abd4c32a5..60564a369 100644 --- a/src/desktop/backends/platform/macos.m +++ b/src/desktop/backends/platform/macos.m @@ -2,16 +2,33 @@ void show_error_box(const char *message) { +#if __has_feature(objc_arc) @autoreleasepool { +#else + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; +#endif + NSAlert *alert = [[NSAlert alloc] init]; [alert setMessageText:@"Error"]; - [alert setInformativeText: - [NSString stringWithUTF8String:message]]; - + [alert setInformativeText:[NSString stringWithUTF8String:message]]; [alert addButtonWithTitle:@"OK"]; + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 [alert setAlertStyle:NSAlertStyleCritical]; +#else + [alert setAlertStyle:NSCriticalAlertStyle]; +#endif [alert runModal]; + +#if !__has_feature(objc_arc) + [alert release]; +#endif + +#if __has_feature(objc_arc) } +#else + [pool drain]; +#endif } \ No newline at end of file From c023893304077f18861dcf51ddcbdcc45fd6c96f Mon Sep 17 00:00:00 2001 From: emiyl Date: Sat, 25 Jul 2026 01:00:10 +0100 Subject: [PATCH 11/16] macos 10.0 compatibility --- src/desktop/backends/platform/macos.m | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/desktop/backends/platform/macos.m b/src/desktop/backends/platform/macos.m index 60564a369..8e5c92cdb 100644 --- a/src/desktop/backends/platform/macos.m +++ b/src/desktop/backends/platform/macos.m @@ -1,4 +1,8 @@ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 #import +#else +#import +#endif void show_error_box(const char *message) { @@ -8,6 +12,8 @@ void show_error_box(const char *message) NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; #endif +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 + NSAlert *alert = [[NSAlert alloc] init]; [alert setMessageText:@"Error"]; @@ -26,9 +32,23 @@ void show_error_box(const char *message) [alert release]; #endif -#if __has_feature(objc_arc) - } #else + + NSRunAlertPanel( + @"Error", + [NSString stringWithUTF8String:message], + @"OK", + nil, + nil + ); + +#endif + +#if !__has_feature(objc_arc) [pool drain]; #endif + +#if __has_feature(objc_arc) + } +#endif } \ No newline at end of file From 19b6569db63501c7fae8a30fefa83edb8c588689 Mon Sep 17 00:00:00 2001 From: emiyl Date: Sat, 25 Jul 2026 01:03:38 +0100 Subject: [PATCH 12/16] separate into two functions --- src/desktop/backends/platform/macos.m | 62 ++++++++++++++++----------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/src/desktop/backends/platform/macos.m b/src/desktop/backends/platform/macos.m index 8e5c92cdb..8bfd40a3c 100644 --- a/src/desktop/backends/platform/macos.m +++ b/src/desktop/backends/platform/macos.m @@ -1,10 +1,9 @@ -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 -#import -#else +#include #import -#endif -void show_error_box(const char *message) +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 + +static void show_error_box_nsalert(const char *message) { #if __has_feature(objc_arc) @autoreleasepool { @@ -12,43 +11,56 @@ void show_error_box(const char *message) NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; #endif -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 - - NSAlert *alert = [[NSAlert alloc] init]; - - [alert setMessageText:@"Error"]; - [alert setInformativeText:[NSString stringWithUTF8String:message]]; - [alert addButtonWithTitle:@"OK"]; + NSAlert *alert = [[NSAlert alloc] init]; + [alert setMessageText:@"Error"]; + [alert setInformativeText:[NSString stringWithUTF8String:message]]; + [alert addButtonWithTitle:@"OK"]; #if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 [alert setAlertStyle:NSAlertStyleCritical]; #else [alert setAlertStyle:NSCriticalAlertStyle]; #endif - [alert runModal]; + [alert runModal]; #if !__has_feature(objc_arc) - [alert release]; + [alert release]; +#endif + +#if !__has_feature(objc_arc) + [pool drain]; +#endif + +#if __has_feature(objc_arc) + } #endif +} #else - NSRunAlertPanel( - @"Error", - [NSString stringWithUTF8String:message], - @"OK", - nil, - nil - ); +static void show_error_box_nsrunalertpanel(const char *message) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; -#endif + NSRunAlertPanel( + @"Error", + [NSString stringWithUTF8String:message], + @"OK", + nil, + nil + ); -#if !__has_feature(objc_arc) [pool drain]; +} + #endif -#if __has_feature(objc_arc) - } +void show_error_box(const char *message) +{ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 + show_error_box_nsalert(message); +#else + show_error_box_nsrunalertpanel(message); #endif } \ No newline at end of file From 9f51a4496c93d683111e35459db57da30916bf8d Mon Sep 17 00:00:00 2001 From: emiyl Date: Sat, 25 Jul 2026 01:04:31 +0100 Subject: [PATCH 13/16] use #include instead of #import --- src/desktop/backends/platform/macos.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/desktop/backends/platform/macos.m b/src/desktop/backends/platform/macos.m index 8bfd40a3c..1475f90e1 100644 --- a/src/desktop/backends/platform/macos.m +++ b/src/desktop/backends/platform/macos.m @@ -1,5 +1,5 @@ #include -#import +#include #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 From dd11dc6bdc591102aeb376cca48b720fbe303c2b Mon Sep 17 00:00:00 2001 From: emiyl Date: Sat, 25 Jul 2026 12:59:33 +0100 Subject: [PATCH 14/16] fix for devices that don't support __has_feature --- src/desktop/backends/platform/macos.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/desktop/backends/platform/macos.m b/src/desktop/backends/platform/macos.m index 1475f90e1..d6c85ddf2 100644 --- a/src/desktop/backends/platform/macos.m +++ b/src/desktop/backends/platform/macos.m @@ -1,6 +1,10 @@ #include #include +#ifndef __has_feature +#define __has_feature(x) 0 +#endif + #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 static void show_error_box_nsalert(const char *message) From fb379432c8ae994e6867a2d70d0a24c6637f9ea9 Mon Sep 17 00:00:00 2001 From: emiyl Date: Sat, 25 Jul 2026 13:33:10 +0100 Subject: [PATCH 15/16] remove arc --- src/desktop/backends/platform/macos.m | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/desktop/backends/platform/macos.m b/src/desktop/backends/platform/macos.m index d6c85ddf2..3702011f6 100644 --- a/src/desktop/backends/platform/macos.m +++ b/src/desktop/backends/platform/macos.m @@ -1,44 +1,25 @@ #include #include -#ifndef __has_feature -#define __has_feature(x) 0 -#endif - -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 // NSAlert is available in 10.3 and later static void show_error_box_nsalert(const char *message) { -#if __has_feature(objc_arc) - @autoreleasepool { -#else NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; -#endif - NSAlert *alert = [[NSAlert alloc] init]; [alert setMessageText:@"Error"]; [alert setInformativeText:[NSString stringWithUTF8String:message]]; [alert addButtonWithTitle:@"OK"]; -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 // NSAlertStyleCritical is available in 10.12 and later [alert setAlertStyle:NSAlertStyleCritical]; #else [alert setAlertStyle:NSCriticalAlertStyle]; #endif [alert runModal]; - -#if !__has_feature(objc_arc) [alert release]; -#endif - -#if !__has_feature(objc_arc) [pool drain]; -#endif - -#if __has_feature(objc_arc) - } -#endif } #else From 1afbef3dd5df6d6dbc9eca9b57423b551b9e453f Mon Sep 17 00:00:00 2001 From: emiyl Date: Sat, 25 Jul 2026 13:48:23 +0100 Subject: [PATCH 16/16] combine to one function --- src/desktop/backends/platform/macos.m | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/desktop/backends/platform/macos.m b/src/desktop/backends/platform/macos.m index 3702011f6..19501fdaa 100644 --- a/src/desktop/backends/platform/macos.m +++ b/src/desktop/backends/platform/macos.m @@ -1,11 +1,12 @@ #include #include -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 // NSAlert is available in 10.3 and later - -static void show_error_box_nsalert(const char *message) +static void show_error_box(const char *message) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 // NSAlert is available in 10.3 and later + NSAlert *alert = [[NSAlert alloc] init]; [alert setMessageText:@"Error"]; @@ -19,15 +20,9 @@ static void show_error_box_nsalert(const char *message) [alert runModal]; [alert release]; - [pool drain]; -} #else -static void show_error_box_nsrunalertpanel(const char *message) -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSRunAlertPanel( @"Error", [NSString stringWithUTF8String:message], @@ -36,16 +31,7 @@ static void show_error_box_nsrunalertpanel(const char *message) nil ); - [pool drain]; -} - #endif -void show_error_box(const char *message) -{ -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 - show_error_box_nsalert(message); -#else - show_error_box_nsrunalertpanel(message); -#endif + [pool drain]; } \ No newline at end of file