From 3eb9c781cf944f1f961c38169c41ea76454867bd Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Fri, 11 Oct 2024 18:50:42 +0200 Subject: [PATCH] impl `Drop` for `Surface` --- wgpu-core/src/instance.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 0aa864eee..9d57c478d 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -427,6 +427,18 @@ impl Surface { } } +impl Drop for Surface { + fn drop(&mut self) { + if let Some(present) = self.presentation.lock().take() { + for (&backend, surface) in &self.surface_per_backend { + if backend == present.device.backend() { + unsafe { surface.unconfigure(present.device.raw()) }; + } + } + } + } +} + pub struct Adapter { pub(crate) raw: hal::DynExposedAdapter, } @@ -768,18 +780,7 @@ impl Global { api_log!("Surface::drop {id:?}"); - let surface = self.surfaces.remove(id); - let surface = - Arc::into_inner(surface).expect("Surface cannot be destroyed because is still in use"); - - if let Some(present) = surface.presentation.lock().take() { - for (&backend, surface) in &surface.surface_per_backend { - if backend == present.device.backend() { - unsafe { surface.unconfigure(present.device.raw()) }; - } - } - } - drop(surface) + self.surfaces.remove(id); } pub fn enumerate_adapters(&self, backends: Backends) -> Vec {