Skip to content

Commit 1d7577f

Browse files
authored
ignore time channel error (#9981)
# Objective - sometimes when bevy shuts down on certain machines the render thread tries to send the time after the main world has been dropped. - fixes an error mentioned in a reply in #9543 --- ## Changelog - ignore disconnected errors from the time channel.
1 parent 9c00443 commit 1d7577f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

crates/bevy_render/src/renderer/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,16 @@ pub fn render_system(world: &mut World) {
8888

8989
// update the time and send it to the app world
9090
let time_sender = world.resource::<TimeSender>();
91-
time_sender.0.try_send(Instant::now()).expect(
92-
"The TimeSender channel should always be empty during render. You might need to add the bevy::core::time_system to your app.",
93-
);
91+
if let Err(error) = time_sender.0.try_send(Instant::now()) {
92+
match error {
93+
bevy_time::TrySendError::Full(_) => {
94+
panic!("The TimeSender channel should always be empty during render. You might need to add the bevy::core::time_system to your app.",);
95+
}
96+
bevy_time::TrySendError::Disconnected(_) => {
97+
// ignore disconnected errors, the main world probably just got dropped during shutdown
98+
}
99+
}
100+
}
94101
}
95102

96103
/// This queue is used to enqueue tasks for the GPU to execute asynchronously.

crates/bevy_time/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub use timer::*;
1717

1818
use bevy_ecs::system::{Res, ResMut};
1919
use bevy_utils::{tracing::warn, Duration, Instant};
20+
pub use crossbeam_channel::TrySendError;
2021
use crossbeam_channel::{Receiver, Sender};
2122

2223
pub mod prelude {

0 commit comments

Comments
 (0)