merge

Thu, 28 May 2026 21:18:33 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 28 May 2026 21:18:33 +0200
changeset 1148
6ebe1b98f53b
parent 1147
30476eaff3ba (current diff)
parent 1146
35e098a663a7 (diff)
child 1149
76b7664f951e

merge

--- a/ui/cocoa/toolkit.m	Thu May 28 21:17:26 2026 +0200
+++ b/ui/cocoa/toolkit.m	Thu May 28 21:18:33 2026 +0200
@@ -50,13 +50,34 @@
 static int app_argc;
 static const char **app_argv;
 
-static UiBool        exit_on_shutdown;
+static UiBool exit_on_shutdown;
+
+static char *main_thread_error_msg;
+
+// This function is only used by language bindings, to improve error messages
+// for example, when using java bindings, this can provide infos how to fix
+// this (-XstartOnFirstThread)
+void ui_set_main_thread_error_msg(const char *msg) {
+    main_thread_error_msg = msg ? strdup(msg) : NULL;
+}
 
 /* ------------------- App Init / Event Loop functions ------------------- */
 
 static AppDelegate *app_delegate;
 
+static void main_thr_check(const char *func) {
+    if(![NSThread isMainThread]) {
+        fprintf(stderr, "Error: %s must run on the main thread.\n", func);
+        if(main_thread_error_msg) {
+            fprintf(stderr, "%s\n", main_thread_error_msg);
+        }
+        exit(1);
+    }
+}
+
 void ui_init(const char *appname, int argc, char **argv) {
+    main_thr_check("ui_init");
+    
     application_name = appname ? strdup(appname) : NULL;
     app_argc = argc;
     app_argv = (const char**)argv;
@@ -124,6 +145,8 @@
 }
 
 void ui_main(void) {
+    main_thr_check("ui_main");
+    
     NSApplicationMain(app_argc, app_argv);
     //[NSApp finishLaunching];
     //[NSApp activateIgnoringOtherApps:YES];
--- a/ui/gtk/toolkit.c	Thu May 28 21:17:26 2026 +0200
+++ b/ui/gtk/toolkit.c	Thu May 28 21:18:33 2026 +0200
@@ -62,6 +62,9 @@
 
 static UiBool        exit_on_shutdown;
 
+// NOOP on most platforms, expect macos
+void ui_set_main_thread_error_msg(const char *msg) {}
+
 UIEXPORT void ui_init(const char *appname, int argc, char **argv) {
     application_name = appname ? strdup(appname) : NULL;
     uic_init_global_context();
--- a/ui/motif/toolkit.c	Thu May 28 21:17:26 2026 +0200
+++ b/ui/motif/toolkit.c	Thu May 28 21:18:33 2026 +0200
@@ -89,6 +89,9 @@
     fallback_resources = fallbackres;
 }
 
+// NOOP on most platforms, expect macos
+void ui_set_main_thread_error_msg(const char *msg) {}
+
 void ui_init(const char *appname, int argc, char **argv) { 
     application_name = appname ? strdup(appname) : NULL;
     uic_init_global_context();
--- a/ui/qt/toolkit.cpp	Thu May 28 21:17:26 2026 +0200
+++ b/ui/qt/toolkit.cpp	Thu May 28 21:18:33 2026 +0200
@@ -48,6 +48,9 @@
 
 static UiBool exit_on_shutdown;
 
+// NOOP on most platforms, expect macos
+extern "C" UIEXPORT void ui_set_main_thread_error_msg(const char *msg) {}
+
 void ui_init(const char *appname, int argc, char **argv) {
     application_name = appname ? strdup(appname) : NULL;
     
--- a/ui/server/toolkit.c	Thu May 28 21:17:26 2026 +0200
+++ b/ui/server/toolkit.c	Thu May 28 21:18:33 2026 +0200
@@ -52,6 +52,9 @@
 static CxMap *srv_obj_map;
 static uint64_t srv_obj_id_counter = 0;
 
+// NOOP on most platforms, expect macos
+void ui_set_main_thread_error_msg(const char *msg) {}
+
 void ui_init(const char *appname, int argc, char **argv) {
     ui_app_name = appname ? strdup(appname) : NULL;
     
--- a/ui/win32/toolkit.c	Thu May 28 21:17:26 2026 +0200
+++ b/ui/win32/toolkit.c	Thu May 28 21:18:33 2026 +0200
@@ -49,6 +49,9 @@
 
 static HFONT ui_font = NULL;
 
+// NOOP on most platforms, expect macos
+UIEXPORT void ui_set_main_thread_error_msg(const char *msg) {}
+
 void ui_init(const char *appname, int argc, char **argv) {
     application_name = appname ? strdup(appname) : NULL;
 
--- a/ui/winui/toolkit.cpp	Thu May 28 21:17:26 2026 +0200
+++ b/ui/winui/toolkit.cpp	Thu May 28 21:18:33 2026 +0200
@@ -149,6 +149,9 @@
 	}
 }
 
+// NOOP on most platforms, expect macos
+UIEXPORT extern "C" void ui_set_main_thread_error_msg(const char *msg) {}
+
 void ui_init(const char* appname, int argc, char** argv) {
 	application_name = appname ? strdup(appname) : NULL;
 

mercurial