Skip to content

Commit

Permalink
Fix random crash on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
leaanthony committed Jul 19, 2024
1 parent f0cec1c commit f94ecab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions mkdocs-website/docs/en/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 15 additions & 6 deletions v3/pkg/application/linux_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand All @@ -1499,15 +1508,15 @@ 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)
message := C.jsc_value_to_string(value)
msg = C.GoString(message)
defer C.g_free(C.gpointer(message))
windowMessageBuffer <- &windowMessage{
windowId: windowID,
windowId: thisWindowID,
message: msg,
}
}
Expand Down

0 comments on commit f94ecab

Please sign in to comment.