Skip to content

Commit 277aa92

Browse files
authored
Add assertions for clocks monotonicity (#9514)
Fixes #3491
1 parent f01b9de commit 277aa92

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

internal/core/animations.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ impl AnimationDriver {
249249
/// Iterates through all animations based on the new time tick and updates their state. This should be called by
250250
/// the windowing system driver for every frame.
251251
pub fn update_animations(&self, new_tick: Instant) {
252-
if self.global_instant.as_ref().get_untracked() != new_tick {
252+
let current_tick = self.global_instant.as_ref().get_untracked();
253+
assert!(current_tick <= new_tick, "The platform's clock is not monotonic!");
254+
if current_tick != new_tick {
253255
self.active_animations.set(false);
254256
self.global_instant.as_ref().set(new_tick);
255257
}

internal/core/platform.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ pub trait Platform {
9494
#[cfg(feature = "std")]
9595
{
9696
let the_beginning = *INITIAL_INSTANT.get_or_init(time::Instant::now);
97-
time::Instant::now() - the_beginning
97+
let now = time::Instant::now();
98+
assert!(now >= the_beginning, "The platform's clock is not monotonic!");
99+
now - the_beginning
98100
}
99101
#[cfg(not(feature = "std"))]
100102
unimplemented!("The platform abstraction must implement `duration_since_start`")

0 commit comments

Comments
 (0)