From 288f8342b11dce8144d781cb3670a4deb3556376 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Fri, 1 May 2020 00:17:51 -0400 Subject: [PATCH] Don't drop the Global on panic --- wgpu-core/src/hub.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index 30d528c879..d61e042e90 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -25,7 +25,7 @@ use wgt::Backend; #[cfg(debug_assertions)] use std::cell::Cell; -use std::{fmt::Debug, marker::PhantomData, ops}; +use std::{fmt::Debug, marker::PhantomData, ops, thread}; /// A simple structure to manage identities of objects. #[derive(Debug)] @@ -553,10 +553,12 @@ impl Global { impl Drop for Global { fn drop(&mut self) { - log::info!("Dropping Global"); - // destroy surfaces - for (_, (surface, _)) in self.surfaces.data.write().map.drain() { - self.instance.destroy_surface(surface); + if !thread::panicking() { + log::info!("Dropping Global"); + // destroy surfaces + for (_, (surface, _)) in self.surfaces.data.write().map.drain() { + self.instance.destroy_surface(surface); + } } } }