Skip to content

Commit

Permalink
avoid panics when history tick is older than last history tick
Browse files Browse the repository at this point in the history
  • Loading branch information
cBournhonesque committed Jan 13, 2025
1 parent 06423de commit f194510
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lightyear/src/client/prediction/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bevy::prelude::{Component, Reflect, Resource};
use bevy::prelude::{ReflectComponent, ReflectResource};
use std::collections::VecDeque;
use std::fmt::Debug;
use tracing::{error, info};
use tracing::{debug, info};

/// Stores a past value in the history buffer
#[derive(Debug, PartialEq, Clone, Default, Reflect)]
Expand Down Expand Up @@ -71,12 +71,12 @@ impl<R> HistoryBuffer<R> {
/// The tick must be strictly more recent than the most recent update in the buffer
pub(crate) fn add(&mut self, tick: Tick, value: Option<R>) {
if let Some(last_tick) = self.peek().map(|(tick, _)| tick) {
assert!(
tick >= *last_tick,
"Tick must be more recent than the last update in the buffer"
);
// assert!(
// tick >= *last_tick,
// "Tick must be more recent than the last update in the buffer"
// );
if *last_tick == tick {
error!("Adding update to history buffer for tick: {:?} but it already had a value for that tick!", tick);
debug!("Adding update to history buffer for tick: {:?} but it already had a value for that tick!", tick);
// in this case, let's pop back the update to replace it with the new value
self.buffer.pop_back();
}
Expand Down

0 comments on commit f194510

Please sign in to comment.