Skip to content

Commit

Permalink
clamping in ui panel
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Apr 8, 2024
1 parent 04c1fa3 commit 4efc432
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions crates/re_query_cache2/src/latest_at/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,27 @@ impl CachedLatestAtComponentResults {
pub fn instance<C: Component>(&self, resolver: &PromiseResolver, index: usize) -> Option<C> {
let component_name = C::name();
let level = re_log::Level::Warn;

match self.to_dense::<C>(resolver).flatten() {
PromiseResult::Pending => {
re_log::debug_once!("Couldn't deserialize {component_name}: promise still pending",);
None
}
PromiseResult::Ready(data) if data.len() > index => Some(data[index].clone()),
PromiseResult::Ready(data) => {
re_log::log_once!(
// TODO(#5303): Figure out we'd like to integrate clamping semantics into selection panel.
//
// For now, we simply always clamp, which is the closest to the legacy behavior that the UI
// expects.
let index = usize::min(index, data.len().saturating_sub(1));

if data.len() <= index {
re_log::log_once!(
level,
"Couldn't deserialize {component_name}: index not found (index: {index}, length: {})",
data.len(),
);
}

None
}
PromiseResult::Error(err) => {
Expand Down

0 comments on commit 4efc432

Please sign in to comment.