Skip to content

Commit

Permalink
WIP: fix panic
Browse files Browse the repository at this point in the history
  • Loading branch information
grtlr committed Nov 20, 2024
1 parent 8e5ab19 commit 3e4327d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions crates/viewer/re_space_view_graph/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ impl Layout {
.get_mut(node)
.expect("node should exist in layout") = rect;
}

/// Returns `true` if any node has a zero size.
pub fn has_zero_size(&self) -> bool {
self.extents.values().any(|r| r.size() == Vec2::ZERO)
}
}

impl<'a> From<&'a NodeInstance> for fj::Node {
Expand Down
11 changes: 11 additions & 0 deletions crates/viewer/re_space_view_graph/src/ui/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use egui::Rect;
use re_chunk::{TimeInt, Timeline};
use re_format::format_f32;
use re_log::external::log;
use re_types::blueprint::components::VisualBounds2D;
use re_ui::UiExt;
use re_viewer_context::SpaceViewState;
Expand Down Expand Up @@ -137,6 +138,16 @@ impl LayoutState {
provider,
}
}
Self::InProgress { ref timestamp, .. } if timestamp != &requested => {
let provider = ForceLayout::new(graphs);
let layout = provider.init_layout();

Self::InProgress {
timestamp: requested,
layout,
provider,
}
}
// We keep iterating on the layout until it is stable.
Self::InProgress {
timestamp,
Expand Down
12 changes: 8 additions & 4 deletions crates/viewer/re_space_view_graph/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ impl SpaceViewClass for GraphSpaceView {
query.latest_at,
graphs.iter().map(|(_, graph)| graph),
);
let needs_remeasure = layout.has_zero_size();

state.world_bounds = Some(bounds);
let bounds_rect: egui::Rect = bounds.into();
Expand All @@ -169,17 +170,16 @@ impl SpaceViewClass for GraphSpaceView {

// Draw explicit nodes.
for node in graph.nodes_explicit() {
let pos = layout.get(&node.index).unwrap_or(egui::Rect::ZERO); // TODO(grtlr): sometimes there just isn't any data.
// .expect("explicit node should be in layout");
let pos = layout.get(&node.index).unwrap_or(egui::Rect::ZERO);

let response = scene.explicit_node(pos.min, node);
entity_rect = entity_rect.union(response.rect);
layout.update(&node.index, response.rect);
}

// Draw implicit nodes.
for node in graph.nodes_implicit() {
let current = layout.get(&node.index).unwrap_or(egui::Rect::ZERO); // TODO(grtlr): sometimes there just isn't any data.
// .expect("implicit node should be in layout");
let current = layout.get(&node.index).unwrap_or(egui::Rect::ZERO);
let response = scene.implicit_node(current.min, node);
entity_rect = entity_rect.union(response.rect);
layout.update(&node.index, response.rect);
Expand Down Expand Up @@ -220,6 +220,10 @@ impl SpaceViewClass for GraphSpaceView {
// Update stored bounds on the state, so visualizers see an up-to-date value.
state.world_bounds = Some(bounds);

if needs_remeasure {
ui.ctx().request_discard("layout needed a remeasure");
}

if state.layout_state.is_in_progress() {
ui.ctx().request_repaint();
}
Expand Down

0 comments on commit 3e4327d

Please sign in to comment.