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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/system/system_piping.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions crates/bevy_transform/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ 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.
// 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);

Expand Down