diff --git a/mkdocs-website/docs/en/changelog.md b/mkdocs-website/docs/en/changelog.md index 7f6e84091..ce1f07c58 100644 --- a/mkdocs-website/docs/en/changelog.md +++ b/mkdocs-website/docs/en/changelog.md @@ -73,6 +73,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix handling of multiple return values from bound methods by [@fbbdev](https://github.com/fbbdev) in [#3431](https://github.com/wailsapp/wails/pull/3431) - Fix doctor detection of npm that is not installed with system package manager by [@pekim](https://github.com/pekim) in [#3458](https://github.com/wailsapp/wails/pull/3458) - Fix missing MicrosoftEdgeWebview2Setup.exe. Thanks to [@robin-samuel](https://github.com/robin-samuel). +- Fix random crash on linux due to window ID handling by @leaanthony. Based on PR [#3466](https://github.com/wailsapp/wails/pull/3622) by [@5aaee9](https://github.com/5aaee9). ### Changed diff --git a/v3/pkg/application/linux_cgo.go b/v3/pkg/application/linux_cgo.go index 3aa44019a..f55daa711 100644 --- a/v3/pkg/application/linux_cgo.go +++ b/v3/pkg/application/linux_cgo.go @@ -56,6 +56,16 @@ typedef struct WindowEvent { uint event; } WindowEvent; +static void save_window_id(void *object, uint value) +{ + g_object_set_data((GObject *)object, "windowid", GUINT_TO_POINTER((guint)value)); +} + +static guint get_window_id(void *object) +{ + return GPOINTER_TO_UINT(g_object_get_data((GObject *)object, "windowid")); +} + // exported below void activateLinux(gpointer data); extern void emit(WindowEvent* data); @@ -991,11 +1001,10 @@ func windowNewWebview(parentId uint, gpuPolicy WebviewGpuPolicy) pointer { manager := C.webkit_user_content_manager_new() C.webkit_user_content_manager_register_script_message_handler(manager, c.String("external")) webView := C.webkit_web_view_new_with_user_content_manager(manager) - winID := unsafe.Pointer(uintptr(C.uint(parentId))) // attach window id to both the webview and contentmanager - C.g_object_set_data((*C.GObject)(unsafe.Pointer(webView)), c.String("windowid"), C.gpointer(winID)) - C.g_object_set_data((*C.GObject)(unsafe.Pointer(manager)), c.String("windowid"), C.gpointer(winID)) + C.save_window_id(unsafe.Pointer(webView), C.uint(parentId)) + C.save_window_id(unsafe.Pointer(manager), C.uint(parentId)) registerURIScheme.Do(func() { context := C.webkit_web_view_get_context(C.webkit_web_view(webView)) @@ -1486,7 +1495,7 @@ func getKeyboardState(event *C.GdkEventKey) (string, bool) { //export onProcessRequest func onProcessRequest(request *C.WebKitURISchemeRequest, data C.uintptr_t) { webView := C.webkit_uri_scheme_request_get_web_view(request) - windowId := uint(uintptr(C.g_object_get_data((*C.GObject)(unsafe.Pointer(webView)), C.CString("windowid")))) + windowId := uint(C.get_window_id(unsafe.Pointer(webView))) webviewRequests <- &webViewAssetRequest{ Request: webview.NewRequest(unsafe.Pointer(request)), windowId: windowId, @@ -1499,7 +1508,7 @@ func sendMessageToBackend(contentManager *C.WebKitUserContentManager, result *C. data unsafe.Pointer) { // Get the windowID from the contentManager - windowID := uint(uintptr(C.g_object_get_data((*C.GObject)(unsafe.Pointer(contentManager)), C.CString("windowid")))) + thisWindowID := uint(C.get_window_id(unsafe.Pointer(contentManager))) var msg string value := C.webkit_javascript_result_get_js_value(result) @@ -1507,7 +1516,7 @@ func sendMessageToBackend(contentManager *C.WebKitUserContentManager, result *C. msg = C.GoString(message) defer C.g_free(C.gpointer(message)) windowMessageBuffer <- &windowMessage{ - windowId: windowID, + windowId: thisWindowID, message: msg, } }