impl Drop for Surface

This commit is contained in:
teoxoy 2024-10-11 18:50:42 +02:00 committed by Teodor Tanasoaia
parent b7d465a2b4
commit 3eb9c781cf

View File

@ -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 struct Adapter {
pub(crate) raw: hal::DynExposedAdapter, pub(crate) raw: hal::DynExposedAdapter,
} }
@ -768,18 +780,7 @@ impl Global {
api_log!("Surface::drop {id:?}"); api_log!("Surface::drop {id:?}");
let surface = self.surfaces.remove(id); 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)
} }
pub fn enumerate_adapters(&self, backends: Backends) -> Vec<AdapterId> { pub fn enumerate_adapters(&self, backends: Backends) -> Vec<AdapterId> {