diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index f3858359ab..0d38931803 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -412,10 +412,10 @@ impl Hub { } } -impl Drop for Hub { - fn drop(&mut self) { +impl Hub { + fn clear(&mut self, surface_guard: &mut Storage) { use crate::resource::TextureViewInner; - use hal::device::Device as _; + use hal::{device::Device as _, window::PresentationSurface as _}; let mut devices = self.devices.data.write(); @@ -489,7 +489,15 @@ impl Drop for Hub { } } - //TODO: self.swap_chains + for (index, (swap_chain, epoch)) in self.swap_chains.data.write().map.drain() { + let device = &devices[swap_chain.device_id.value]; + let surface = &mut surface_guard[TypedId::zip(index as Index, epoch, B::VARIANT)]; + let suf = B::get_surface_mut(surface); + unsafe { + device.raw.destroy_semaphore(swap_chain.semaphore); + suf.unconfigure_swapchain(&device.raw); + } + } for (_, (device, _)) in devices.map.drain() { device.dispose(); @@ -551,8 +559,21 @@ impl Drop for Global { fn drop(&mut self) { if !thread::panicking() { log::info!("Dropping Global"); + let mut surface_guard = self.surfaces.data.write(); + // destroy hubs + #[cfg(any( + not(any(target_os = "ios", target_os = "macos")), + feature = "gfx-backend-vulkan" + ))] + self.hubs.vulkan.clear(&mut *surface_guard); + #[cfg(any(target_os = "ios", target_os = "macos"))] + self.hubs.metal.clear(&mut *surface_guard); + #[cfg(windows)] + self.hubs.dx12.clear(&mut *surface_guard); + #[cfg(windows)] + self.hubs.dx11.clear(&mut *surface_guard); // destroy surfaces - for (_, (surface, _)) in self.surfaces.data.write().map.drain() { + for (_, (surface, _)) in surface_guard.map.drain() { self.instance.destroy_surface(surface); } }