mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Properly destroy swap chains
This commit is contained in:
@@ -416,10 +416,10 @@ impl<B: GfxBackend, F: GlobalIdentityHandlerFactory> Hub<B, F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: hal::Backend, F: GlobalIdentityHandlerFactory> Drop for Hub<B, F> {
|
||||
fn drop(&mut self) {
|
||||
impl<B: GfxBackend, F: GlobalIdentityHandlerFactory> Hub<B, F> {
|
||||
fn clear(&mut self, surface_guard: &mut Storage<Surface, SurfaceId>) {
|
||||
use crate::resource::TextureViewInner;
|
||||
use hal::device::Device as _;
|
||||
use hal::{device::Device as _, window::PresentationSurface as _};
|
||||
|
||||
let mut devices = self.devices.data.write();
|
||||
|
||||
@@ -493,7 +493,15 @@ impl<B: hal::Backend, F: GlobalIdentityHandlerFactory> Drop for Hub<B, F> {
|
||||
}
|
||||
}
|
||||
|
||||
//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();
|
||||
@@ -555,8 +563,21 @@ impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user