animation: fix crash with zero-duration animations
This commit is contained in:
@@ -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<T> Animation<T> {
|
||||
impl<T: core::fmt::Debug> Animation<T> {
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
from: None,
|
||||
@@ -128,12 +128,14 @@ impl<T> Animation<T> {
|
||||
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<T> Animation<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
Reference in New Issue
Block a user