From d86fdb48d1957d2da89c786334c4a99c6825f659 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Sat, 28 Jan 2017 15:14:23 +0100 Subject: [PATCH] Remove the window from the events loop on destruction --- src/api_transition.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/api_transition.rs b/src/api_transition.rs index 09788296..4841ada6 100644 --- a/src/api_transition.rs +++ b/src/api_transition.rs @@ -56,6 +56,7 @@ macro_rules! gen_api_transition { pub struct Window2 { window: ::std::sync::Arc, + events_loop: ::std::sync::Weak, } impl ::std::ops::Deref for Window2 { @@ -75,6 +76,7 @@ macro_rules! gen_api_transition { events_loop.windows.lock().unwrap().push(win.clone()); Ok(Window2 { window: win, + events_loop: ::std::sync::Arc::downgrade(&events_loop), }) } @@ -83,5 +85,14 @@ macro_rules! gen_api_transition { &*self.window as *const Window as usize } } + + impl Drop for Window2 { + fn drop(&mut self) { + if let Some(ev) = self.events_loop.upgrade() { + let mut windows = ev.windows.lock().unwrap(); + windows.retain(|w| &**w as *const Window != &*self.window as *const _); + } + } + } }; }