Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - TaskPool Panic Handling #6443

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/system/system_piping.rs
Expand Up @@ -202,7 +202,7 @@ pub mod adapter {
/// // Building a new schedule/app...
/// # use bevy_ecs::schedule::SystemStage;
/// # let mut sched = Schedule::default(); sched
/// # .add_stage(CoreStage::Update, SystemStage::single_threaded())
/// # .add_stage(CoreStage::Update, SystemStage::parallel())
james7132 marked this conversation as resolved.
Show resolved Hide resolved
/// .add_system_to_stage(
/// CoreStage::Update,
/// // Panic if the load system returns an error.
Expand Down Expand Up @@ -246,7 +246,7 @@ pub mod adapter {
/// // Building a new schedule/app...
/// # use bevy_ecs::schedule::SystemStage;
/// # let mut sched = Schedule::default(); sched
/// # .add_stage(CoreStage::Update, SystemStage::single_threaded())
/// # .add_stage(CoreStage::Update, SystemStage::parallel())
/// .add_system_to_stage(
/// CoreStage::Update,
/// // If the system fails, just move on and try again next frame.
Expand Down
21 changes: 14 additions & 7 deletions crates/bevy_tasks/src/task_pool.rs
Expand Up @@ -118,14 +118,21 @@ impl TaskPool {
thread_builder
.spawn(move || {
TaskPool::LOCAL_EXECUTOR.with(|local_executor| {
let tick_forever = async move {
loop {
local_executor.tick().await;
loop {
let res = std::panic::catch_unwind(|| {
let tick_forever = async move {
loop {
local_executor.tick().await;
}
};
future::block_on(ex.run(tick_forever.or(shutdown_rx.recv())))
});
if let Ok(value) = res {
// Use unwrap_err because we expect a Closed error
value.unwrap_err();
break;
}
};
let shutdown_future = ex.run(tick_forever.or(shutdown_rx.recv()));
// Use unwrap_err because we expect a Closed error
future::block_on(shutdown_future).unwrap_err();
}
});
})
.expect("Failed to spawn thread.")
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_time/src/time.rs
Expand Up @@ -120,7 +120,7 @@ impl Time {
/// world.insert_resource(time);
/// world.insert_resource(Health { health_value: 0.2 });
///
/// let mut update_stage = SystemStage::single_threaded();
/// let mut update_stage = SystemStage::parallel();
/// update_stage.add_system(health_system);
///
/// // Simulate that 30 ms have passed
Expand Down
5 changes: 1 addition & 4 deletions crates/bevy_transform/src/systems.rs
Expand Up @@ -318,10 +318,7 @@ mod test {
let mut temp = World::new();
let mut app = App::new();

// Adding the system in a single threaded stage. As the system will panic, this will
// only bring down the current test thread.
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);
Expand Down