From 73e07739422e2e530cb3c7857dd208bf1184448f Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Tue, 24 Mar 2026 12:40:01 +0100 Subject: [PATCH] animation: fix crash with zero-duration animations --- src/animation.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/animation.rs b/src/animation.rs index 5e36d39..2a88e35 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -115,7 +115,7 @@ struct Animator<'a, T, const ACTOR_COUNT: usize> { impl<'a, T, const ACTOR_COUNT: usize> Animator<'a, T, ACTOR_COUNT> { } -impl Animation { +impl Animation { pub const fn new() -> Self { Self { from: None, @@ -128,12 +128,14 @@ impl Animation { let mut now: Instant = Instant::now(); loop { // Find the next shortest delay - let mut next_keyframe_time = animators[0].next_update; + let mut next_keyframe_time = Instant::MAX; let mut finished = false; + let mut has_valid = false; for animator in &mut animators { if !animator.is_valid() { continue; } + has_valid = true; if animator.next_update <= now { finished = match animator.tick() { TickResult::Finished => true, @@ -146,10 +148,13 @@ impl Animation { } } + // If there are no valid animators, or if all animators are finished, then we're done + finished |= !has_valid; if finished { break; } + assert!(next_keyframe_time > now, "Weird times: {next_keyframe_time:?} is earlier than {now:?} animators={animators:?}"); let keyframe_delay = next_keyframe_time - now; trace!("delay {:?}", keyframe_delay.as_millis()); Timer::after(keyframe_delay).await;