From 3e4327ddbf19973812e19a0449711c8160f7670e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20G=C3=B6rtler?= Date: Wed, 20 Nov 2024 20:20:23 +0100 Subject: [PATCH] WIP: fix panic --- crates/viewer/re_space_view_graph/src/layout/mod.rs | 5 +++++ crates/viewer/re_space_view_graph/src/ui/state.rs | 11 +++++++++++ crates/viewer/re_space_view_graph/src/view.rs | 12 ++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/crates/viewer/re_space_view_graph/src/layout/mod.rs b/crates/viewer/re_space_view_graph/src/layout/mod.rs index 5d13b5d33806..1fb86dcef958 100644 --- a/crates/viewer/re_space_view_graph/src/layout/mod.rs +++ b/crates/viewer/re_space_view_graph/src/layout/mod.rs @@ -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 { diff --git a/crates/viewer/re_space_view_graph/src/ui/state.rs b/crates/viewer/re_space_view_graph/src/ui/state.rs index 499236f62bbd..ff23e75773e0 100644 --- a/crates/viewer/re_space_view_graph/src/ui/state.rs +++ b/crates/viewer/re_space_view_graph/src/ui/state.rs @@ -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; @@ -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, diff --git a/crates/viewer/re_space_view_graph/src/view.rs b/crates/viewer/re_space_view_graph/src/view.rs index b51018243da5..5bb9c17a697f 100644 --- a/crates/viewer/re_space_view_graph/src/view.rs +++ b/crates/viewer/re_space_view_graph/src/view.rs @@ -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(); @@ -169,8 +170,8 @@ 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); @@ -178,8 +179,7 @@ impl SpaceViewClass for GraphSpaceView { // 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); @@ -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(); }