From c7ddec571da35b28f0324de86fa97cba9c9de628 Mon Sep 17 00:00:00 2001 From: Zachary Harrold Date: Thu, 23 Jan 2025 13:44:16 +1100 Subject: [PATCH] Fix Time (#17504) # Objective - Fix issue @mockersf identified with `example-showcase` where time was not being received correctly from the render world. ## Solution - Refactored to ensure `TimeReceiver` is always cleared even if it isn't being used in the main world. ## Testing - `cargo run -p example-showcase -- --page 1 --per-page 1 run --screenshot-frame 200 --fixed-frame-time 0.0125 --stop-frame 450 --in-ci --show-logs` --- crates/bevy_time/src/lib.rs | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/crates/bevy_time/src/lib.rs b/crates/bevy_time/src/lib.rs index d50302b560..334ff549a9 100644 --- a/crates/bevy_time/src/lib.rs +++ b/crates/bevy_time/src/lib.rs @@ -144,28 +144,28 @@ pub fn time_system( #[cfg(feature = "std")] time_recv: Option>, #[cfg(feature = "std")] mut has_received_time: Local, ) { + #[cfg(feature = "std")] + // TODO: Figure out how to handle this when using pipelined rendering. + let sent_time = match time_recv.map(|res| res.0.try_recv()) { + Some(Ok(new_time)) => { + *has_received_time = true; + Some(new_time) + } + Some(Err(_)) => { + if *has_received_time { + log::warn!("time_system did not receive the time from the render world! Calculations depending on the time may be incorrect."); + } + None + } + None => None, + }; + + #[cfg(not(feature = "std"))] + let sent_time = None; + match update_strategy.as_ref() { TimeUpdateStrategy::Automatic => { - #[cfg(feature = "std")] - let new_time = if let Some(time_recv) = time_recv { - // TODO: Figure out how to handle this when using pipelined rendering. - if let Ok(new_time) = time_recv.0.try_recv() { - *has_received_time = true; - new_time - } else { - if *has_received_time { - log::warn!("time_system did not receive the time from the render world! Calculations depending on the time may be incorrect."); - } - Instant::now() - } - } else { - Instant::now() - }; - - #[cfg(not(feature = "std"))] - let new_time = Instant::now(); - - real_time.update_with_instant(new_time); + real_time.update_with_instant(sent_time.unwrap_or_else(Instant::now)); } TimeUpdateStrategy::ManualInstant(instant) => real_time.update_with_instant(*instant), TimeUpdateStrategy::ManualDuration(duration) => real_time.update_with_duration(*duration),