From 14d44c2d84f3a67171a8376ef7aa862e6786e2aa Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sun, 3 May 2020 23:39:05 -0400 Subject: [PATCH] Wait for idle before destroying swapchains --- wgpu-core/src/device/mod.rs | 15 +++++++++------ wgpu-core/src/hub.rs | 3 +++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 062f072b30..eacc4e8fd3 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -460,11 +460,14 @@ impl Device { } } + /// Wait for idle and remove resources that we can, before we die. + pub(crate) fn prepare_to_die(&mut self) { + let mut life_tracker = self.life_tracker.lock(); + life_tracker.triage_submissions(&self.raw, true); + life_tracker.cleanup(&self.raw, &self.mem_allocator, &self.desc_allocator); + } + pub(crate) fn dispose(self) { - self.life_tracker.lock().triage_submissions(&self.raw, true); - self.life_tracker - .lock() - .cleanup(&self.raw, &self.mem_allocator, &self.desc_allocator); self.com_allocator.destroy(&self.raw); let mut desc_alloc = self.desc_allocator.into_inner(); let mut mem_alloc = self.mem_allocator.into_inner(); @@ -2104,8 +2107,8 @@ impl Global { let hub = B::hub(self); let mut token = Token::root(); let device = { - let (device, mut token) = hub.devices.unregister(device_id, &mut token); - device.maintain(self, true, &mut token); + let (mut device, _) = hub.devices.unregister(device_id, &mut token); + device.prepare_to_die(); device }; diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index 0d38931803..fd0f5e6530 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -418,6 +418,9 @@ impl Hub { use hal::{device::Device as _, window::PresentationSurface as _}; let mut devices = self.devices.data.write(); + for (device, _) in devices.map.values_mut() { + device.prepare_to_die(); + } for (_, (sampler, _)) in self.samplers.data.write().map.drain() { unsafe {