From efbeacfa690eea19f8ca4bcbc6143c2969e0f1a5 Mon Sep 17 00:00:00 2001 From: James Liu Date: Mon, 21 Nov 2022 12:59:08 +0000 Subject: [PATCH] Fix panicking on another scope (#6524) # Objective Fix #6453. ## Solution Use the solution mentioned in the issue by catching the unwind and dropping the error. Wrap the `executor.try_tick` calls with `std::catch::unwind`. Ideally this would be moved outside of the hot loop, but the mut ref to the `spawned` future is not `UnwindSafe`. This PR only addresses the bug, we can address the perf issues (should there be any) later. --- crates/bevy_tasks/src/task_pool.rs | 7 +++++-- crates/bevy_transform/src/systems.rs | 5 +---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/bevy_tasks/src/task_pool.rs b/crates/bevy_tasks/src/task_pool.rs index 39308c2bfd7bc..2ef244407af77 100644 --- a/crates/bevy_tasks/src/task_pool.rs +++ b/crates/bevy_tasks/src/task_pool.rs @@ -299,8 +299,11 @@ impl TaskPool { break result; }; - self.executor.try_tick(); - task_scope_executor.try_tick(); + std::panic::catch_unwind(|| { + executor.try_tick(); + task_scope_executor.try_tick(); + }) + .ok(); } } } diff --git a/crates/bevy_transform/src/systems.rs b/crates/bevy_transform/src/systems.rs index f96b56d676447..6b802f585bee9 100644 --- a/crates/bevy_transform/src/systems.rs +++ b/crates/bevy_transform/src/systems.rs @@ -318,10 +318,7 @@ mod test { let mut temp = World::new(); let mut app = App::new(); - // FIXME: Parallel executors seem to have some odd interaction with the other - // tests in this crate. Using single_threaded until a root cause can be found. - app.add_stage("single", SystemStage::single_threaded()) - .add_system_to_stage("single", transform_propagate_system); + app.add_system(transform_propagate_system); fn setup_world(world: &mut World) -> (Entity, Entity) { let mut grandchild = Entity::from_raw(0);