diff --git a/wezterm-gui/src/frontend.rs b/wezterm-gui/src/frontend.rs index 62afcc99a..d3e2a10f1 100644 --- a/wezterm-gui/src/frontend.rs +++ b/wezterm-gui/src/frontend.rs @@ -277,6 +277,10 @@ thread_local! { static FRONT_END: RefCell>> = RefCell::new(None); } +pub fn try_front_end() -> Option> { + FRONT_END.with(|f| f.borrow().as_ref().map(Rc::clone)) +} + pub fn front_end() -> Rc { FRONT_END .with(|f| f.borrow().as_ref().map(Rc::clone)) diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index 4f7d30b56..afeba33ac 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -3,7 +3,7 @@ use super::renderstate::*; use super::utilsprites::RenderMetrics; use crate::cache::LruCache; use crate::colorease::ColorEase; -use crate::frontend::front_end; +use crate::frontend::{front_end, try_front_end}; use crate::glium::texture::SrgbTexture2d; use crate::inputmap::InputMap; use crate::overlay::{ @@ -2892,7 +2892,9 @@ impl TermWindow { impl Drop for TermWindow { fn drop(&mut self) { if let Some(window) = self.window.take() { - front_end().forget_known_window(&window); + if let Some(fe) = try_front_end() { + fe.forget_known_window(&window); + } } } } diff --git a/window/src/os/wayland/connection.rs b/window/src/os/wayland/connection.rs index 146d0f8a0..b7bf6d9b3 100644 --- a/window/src/os/wayland/connection.rs +++ b/window/src/os/wayland/connection.rs @@ -264,14 +264,8 @@ impl WaylandConnection { future } -} -impl ConnectionOps for WaylandConnection { - fn terminate_message_loop(&self) { - *self.should_terminate.borrow_mut() = true; - } - - fn run_message_loop(&self) -> anyhow::Result<()> { + fn run_message_loop_impl(&self) -> anyhow::Result<()> { const TOK_WL: usize = 0xffff_fffc; const TOK_SPAWN: usize = 0xffff_fffd; let tok_wl = Token(TOK_WL); @@ -343,8 +337,21 @@ impl ConnectionOps for WaylandConnection { } } } - self.windows.borrow_mut().clear(); - Ok(()) } } + +impl ConnectionOps for WaylandConnection { + fn terminate_message_loop(&self) { + *self.should_terminate.borrow_mut() = true; + } + + fn run_message_loop(&self) -> anyhow::Result<()> { + let res = self.run_message_loop_impl(); + // Ensure that we drop these eagerly, to avoid + // noisy errors wrt. global destructors unwinding + // in unexpected places + self.windows.borrow_mut().clear(); + res + } +}