From cd623dffa83b51290761e4bbccc0c3f7904fd59e Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 11 May 2022 06:52:52 -0700 Subject: [PATCH] fix xcb raising a fatal error when closing a window The rust xcb bindings seem to have gotten more strict in 1.x; previously we might generate two DestroyWindow calls for the same window when closing one and things were fine, but now the second call generates a protocol error which has the effect of terminating the program. This commit ensures that we only generate a single DestroyWindow call by zeroing out the saved window_id after we emit it. refs: #1974 --- window/src/os/x11/window.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/window/src/os/x11/window.rs b/window/src/os/x11/window.rs index bf3829cf9..a979e0fe3 100644 --- a/window/src/os/x11/window.rs +++ b/window/src/os/x11/window.rs @@ -77,10 +77,12 @@ pub(crate) struct XWindowInner { impl Drop for XWindowInner { fn drop(&mut self) { - if let Some(conn) = self.conn.upgrade() { - conn.send_request(&xcb::x::DestroyWindow { - window: self.window_id, - }); + if self.window_id != xcb::x::Window::none() { + if let Some(conn) = self.conn.upgrade() { + conn.send_request(&xcb::x::DestroyWindow { + window: self.window_id, + }); + } } } } @@ -1038,6 +1040,10 @@ impl XWindowInner { self.conn().conn().send_request(&xcb::x::DestroyWindow { window: self.window_id, }); + // Ensure that we don't try to destroy the window twice, + // otherwise the rust xcb bindings will generate a + // fatal error! + self.window_id = xcb::x::Window::none(); } fn hide(&mut self) {} fn show(&mut self) {