Don't drop the Global on panic

This commit is contained in:
Dzmitry Malyshau 2020-05-01 00:17:51 -04:00 committed by Dzmitry Malyshau
parent daaef24b15
commit 74acda9e11
2 changed files with 11 additions and 13 deletions

View File

@ -25,7 +25,7 @@ use wgt::Backend;
#[cfg(debug_assertions)]
use std::cell::Cell;
use std::{fmt::Debug, iter, marker::PhantomData, ops};
use std::{fmt::Debug, iter, marker::PhantomData, ops, thread};
/// A simple structure to manage identities of objects.
#[derive(Debug)]
@ -545,17 +545,16 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
hubs: Hubs::new(&factory),
}
}
}
pub fn delete(self) {
let Global {
mut instance,
surfaces,
hubs,
} = self;
drop(hubs);
// destroy surfaces
for (_, (surface, _)) in surfaces.data.write().map.drain() {
instance.destroy_surface(surface);
impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> {
fn drop(&mut self) {
if !thread::panicking() {
log::info!("Dropping Global");
// destroy surfaces
for (_, (surface, _)) in self.surfaces.data.write().map.drain() {
self.instance.destroy_surface(surface);
}
}
}
}

View File

@ -24,8 +24,7 @@ pub extern "C" fn wgpu_server_new(factory: IdentityRecyclerFactory) -> *mut Glob
#[no_mangle]
pub unsafe extern "C" fn wgpu_server_delete(global: *mut Global) {
log::info!("Terminating WGPU server");
Box::from_raw(global).delete();
log::info!("\t...done");
let _ = Box::from_raw(global);
}
#[no_mangle]