mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added scopeguard to protect against unwind
This commit is contained in:
parent
74ec5c652a
commit
4b1c033f6e
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -5637,6 +5637,7 @@ dependencies = [
|
||||
"indexmap",
|
||||
"rand 0.8.3",
|
||||
"rayon",
|
||||
"scopeguard",
|
||||
"serde",
|
||||
"slab",
|
||||
"specs",
|
||||
|
@ -35,6 +35,7 @@ serde = { version = "1.0.110", features = ["derive"] }
|
||||
tracy-client = { version = "0.10.0", optional = true }
|
||||
|
||||
# Plugins
|
||||
scopeguard = "1.1.0"
|
||||
toml = { version = "0.5.7", optional = true }
|
||||
tar = { version = "0.4.30", optional = true }
|
||||
wasmer = { version = "1.0.0", optional = true, default-features = false, features = ["wat", "default-cranelift", "default-jit"] }
|
||||
|
@ -23,12 +23,14 @@ impl EcsAccessManager {
|
||||
// This function take a World reference and a function to execute ensuring the
|
||||
// pointer will never be corrupted during the execution of the function!
|
||||
pub fn execute_with<T>(&self, world: &World, func: impl FnOnce() -> T) -> T {
|
||||
let _guard = scopeguard::guard((), |_| {
|
||||
// ensure the pointer is cleared in any case
|
||||
self.ecs_pointer
|
||||
.store(std::ptr::null_mut(), Ordering::Relaxed);
|
||||
});
|
||||
self.ecs_pointer
|
||||
.store(world as *const _ as *mut _, Ordering::Relaxed);
|
||||
let out = func();
|
||||
self.ecs_pointer
|
||||
.store(std::ptr::null_mut(), Ordering::Relaxed);
|
||||
out
|
||||
func()
|
||||
}
|
||||
|
||||
/// This unsafe function returns a reference to the Ecs World
|
||||
|
Loading…
Reference in New Issue
Block a user