From bc8c98d7d6b0d065f8a250d41cfbe10050c487bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Steinh=C3=A4user?= Date: Mon, 2 Mar 2026 08:41:49 +0100 Subject: [PATCH] Handle X11 errors during webview destruction on Linux to prevent crashes. --- wrywebview/src/main/rust/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wrywebview/src/main/rust/lib.rs b/wrywebview/src/main/rust/lib.rs index 9369b72..83c847b 100644 --- a/wrywebview/src/main/rust/lib.rs +++ b/wrywebview/src/main/rust/lib.rs @@ -979,6 +979,19 @@ pub fn close_dev_tools(id: u64) -> Result<(), WebViewError> { fn destroy_webview_inner(id: u64) -> Result<(), WebViewError> { wry_log!("[wrywebview] destroy_webview id={}", id); + + #[cfg(target_os = "linux")] + { + gdk::error_trap_push(); + let res = unregister(id); + while gtk::events_pending() { + gtk::main_iteration_do(false); + } + let _ = gdk::error_trap_pop(); + res + } + + #[cfg(not(target_os = "linux"))] unregister(id) }