mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
Don't drop the Global on panic
This commit is contained in:
parent
daaef24b15
commit
74acda9e11
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user