diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index 3e0f759cb..f3858359a 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -25,7 +25,7 @@ use wgt::Backend; #[cfg(debug_assertions)] use std::cell::Cell; -use std::{fmt::Debug, iter, marker::PhantomData, ops}; +use std::{fmt::Debug, iter, marker::PhantomData, ops, thread}; /// A simple structure to manage identities of objects. #[derive(Debug)] @@ -545,17 +545,16 @@ impl Global { hubs: Hubs::new(&factory), } } +} - pub fn delete(self) { - let Global { - mut instance, - surfaces, - hubs, - } = self; - drop(hubs); - // destroy surfaces - for (_, (surface, _)) in surfaces.data.write().map.drain() { - instance.destroy_surface(surface); +impl Drop for Global { + fn drop(&mut self) { + if !thread::panicking() { + log::info!("Dropping Global"); + // destroy surfaces + for (_, (surface, _)) in self.surfaces.data.write().map.drain() { + self.instance.destroy_surface(surface); + } } } } diff --git a/wgpu-remote/src/server.rs b/wgpu-remote/src/server.rs index 8dc6bd4bb..4ff102301 100644 --- a/wgpu-remote/src/server.rs +++ b/wgpu-remote/src/server.rs @@ -24,8 +24,7 @@ pub extern "C" fn wgpu_server_new(factory: IdentityRecyclerFactory) -> *mut Glob #[no_mangle] pub unsafe extern "C" fn wgpu_server_delete(global: *mut Global) { log::info!("Terminating WGPU server"); - Box::from_raw(global).delete(); - log::info!("\t...done"); + let _ = Box::from_raw(global); } #[no_mangle]