Skip to content

Commit

Permalink
impl Drop for Surface
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy committed Oct 14, 2024
1 parent b7d465a commit 3eb9c78
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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<AdapterId> {
Expand Down

0 comments on commit 3eb9c78

Please sign in to comment.