animation: fix crash with zero-duration animations

This commit is contained in:
2026-03-24 12:40:01 +01:00
parent e18425e0ca
commit 73e0773942

View File

@@ -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<'a, T, const ACTOR_COUNT: usize> Animator<'a, T, ACTOR_COUNT> {
} }
impl<T> Animation<T> { impl<T: core::fmt::Debug> Animation<T> {
pub const fn new() -> Self { pub const fn new() -> Self {
Self { Self {
from: None, from: None,
@@ -128,12 +128,14 @@ impl<T> Animation<T> {
let mut now: Instant = Instant::now(); let mut now: Instant = Instant::now();
loop { loop {
// Find the next shortest delay // 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 finished = false;
let mut has_valid = false;
for animator in &mut animators { for animator in &mut animators {
if !animator.is_valid() { if !animator.is_valid() {
continue; continue;
} }
has_valid = true;
if animator.next_update <= now { if animator.next_update <= now {
finished = match animator.tick() { finished = match animator.tick() {
TickResult::Finished => true, TickResult::Finished => true,
@@ -146,10 +148,13 @@ impl<T> Animation<T> {
} }
} }
// If there are no valid animators, or if all animators are finished, then we're done
finished |= !has_valid;
if finished { if finished {
break; break;
} }
assert!(next_keyframe_time > now, "Weird times: {next_keyframe_time:?} is earlier than {now:?} animators={animators:?}");
let keyframe_delay = next_keyframe_time - now; let keyframe_delay = next_keyframe_time - now;
trace!("delay {:?}", keyframe_delay.as_millis()); trace!("delay {:?}", keyframe_delay.as_millis());
Timer::after(keyframe_delay).await; Timer::after(keyframe_delay).await;