diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index b12b2528ad..3d92bfeb63 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -26,7 +26,7 @@ use crate::id::QuerySetId; use crate::resource::QuerySet; #[cfg(debug_assertions)] use std::cell::Cell; -use std::{fmt::Debug, marker::PhantomData, ops, thread}; +use std::{fmt::Debug, marker::PhantomData, ops}; /// A simple structure to manage identities of objects. #[derive(Debug)] @@ -783,38 +783,36 @@ impl Global { impl Drop for Global { fn drop(&mut self) { - if !thread::panicking() { - profiling::scope!("drop", "Global"); - log::info!("Dropping Global"); - let mut surface_guard = self.surfaces.data.write(); + profiling::scope!("drop", "Global"); + log::info!("Dropping Global"); + let mut surface_guard = self.surfaces.data.write(); - // destroy hubs - #[cfg(vulkan)] - { - self.hubs.vulkan.clear(&mut *surface_guard, true); - } - #[cfg(metal)] - { - self.hubs.metal.clear(&mut *surface_guard, true); - } - #[cfg(dx12)] - { - self.hubs.dx12.clear(&mut *surface_guard, true); - } - #[cfg(dx11)] - { - self.hubs.dx11.clear(&mut *surface_guard, true); - } - #[cfg(gl)] - { - self.hubs.gl.clear(&mut *surface_guard, true); - } + // destroy hubs before the instance gets dropped + #[cfg(vulkan)] + { + self.hubs.vulkan.clear(&mut *surface_guard, true); + } + #[cfg(metal)] + { + self.hubs.metal.clear(&mut *surface_guard, true); + } + #[cfg(dx12)] + { + self.hubs.dx12.clear(&mut *surface_guard, true); + } + #[cfg(dx11)] + { + self.hubs.dx11.clear(&mut *surface_guard, true); + } + #[cfg(gl)] + { + self.hubs.gl.clear(&mut *surface_guard, true); + } - // destroy surfaces - for element in surface_guard.map.drain(..) { - if let Element::Occupied(surface, _) = element { - self.instance.destroy_surface(surface); - } + // destroy surfaces + for element in surface_guard.map.drain(..) { + if let Element::Occupied(surface, _) = element { + self.instance.destroy_surface(surface); } } }