fix: ensure that arena is reestablished for cleanups

This commit is contained in:
Greg Johnston
2025-06-12 17:13:12 -04:00
parent c3efb8e476
commit 6be3266a2e

View File

@@ -291,12 +291,18 @@ impl Owner {
/// fill the same need as an "on unmount" function in other UI approaches, etc.
pub fn on_cleanup(fun: impl FnOnce() + Send + Sync + 'static) {
if let Some(owner) = Owner::current() {
owner
.inner
.write()
.or_poisoned()
.cleanups
.push(Box::new(fun));
let mut inner = owner.inner.write().or_poisoned();
#[cfg(feature = "sandboxed-arenas")]
let fun = {
let arena = Arc::clone(&inner.arena);
move || {
Arena::set(&arena);
fun()
}
};
inner.cleanups.push(Box::new(fun));
}
}