Skip to content

Commit

Permalink
Early-out on zero-sized space-views to prevent crashes (#1623)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk authored Mar 20, 2023
1 parent 28b526e commit ed689ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/re_viewer/src/ui/space_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ impl SpaceView {
) {
crate::profile_function!();

let is_zero_sized_viewport = ui.available_size().min_elem() <= 0.0;
if is_zero_sized_viewport {
return;
}

let query = crate::ui::scene::SceneQuery {
entity_paths: self.data_blueprint.entity_paths(),
timeline: *ctx.rec_cfg.time_ctrl.timeline(),
Expand Down
4 changes: 4 additions & 0 deletions crates/re_viewer/src/ui/view_spatial/ui_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ fn view_2d_scrollable(
let (mut response, painter) =
parent_ui.allocate_painter(desired_size, egui::Sense::click_and_drag());

if !response.rect.is_positive() {
return response; // protect against problems with zero-sized views
}

// Create our transforms.
let ui_from_space = egui::emath::RectTransform::from_to(scene_rect_accum, response.rect);
let space_from_ui = ui_from_space.inverse();
Expand Down
4 changes: 4 additions & 0 deletions crates/re_viewer/src/ui/view_spatial/ui_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ pub fn view_3d(
let (rect, mut response) =
ui.allocate_at_least(ui.available_size(), egui::Sense::click_and_drag());

if !rect.is_positive() {
return; // protect against problems with zero-sized views
}

// If we're tracking a camera right now, we want to make it slightly sticky,
// so that a click on some entity doesn't immediately break the tracked state.
// (Threshold is in amount of ui points the mouse was moved.)
Expand Down

1 comment on commit ed689ed

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Benchmark

Benchmark suite Current: ed689ed Previous: c11266d Ratio
datastore/insert/batch/rects/insert 555120 ns/iter (± 5301) 569890 ns/iter (± 5117) 0.97
datastore/latest_at/batch/rects/query 1866 ns/iter (± 103) 1847 ns/iter (± 7) 1.01
datastore/latest_at/missing_components/primary 287 ns/iter (± 1) 286 ns/iter (± 0) 1.00
datastore/latest_at/missing_components/secondaries 439 ns/iter (± 0) 437 ns/iter (± 1) 1.00
datastore/range/batch/rects/query 151372 ns/iter (± 1776) 151525 ns/iter (± 590) 1.00
mono_points_arrow/generate_message_bundles 43705628 ns/iter (± 1124335) 47038586 ns/iter (± 445166) 0.93
mono_points_arrow/generate_messages 125542643 ns/iter (± 1463236) 126571836 ns/iter (± 1139996) 0.99
mono_points_arrow/encode_log_msg 151954105 ns/iter (± 1090468) 155688066 ns/iter (± 1167620) 0.98
mono_points_arrow/encode_total 322659172 ns/iter (± 2590707) 326075244 ns/iter (± 3372422) 0.99
mono_points_arrow/decode_log_msg 172908228 ns/iter (± 1608260) 175971954 ns/iter (± 2901412) 0.98
mono_points_arrow/decode_message_bundles 63649144 ns/iter (± 736220) 65454880 ns/iter (± 843675) 0.97
mono_points_arrow/decode_total 236095652 ns/iter (± 2271402) 241183061 ns/iter (± 2414102) 0.98
batch_points_arrow/generate_message_bundles 320796 ns/iter (± 3750) 328025 ns/iter (± 1133) 0.98
batch_points_arrow/generate_messages 6410 ns/iter (± 73) 6493 ns/iter (± 43) 0.99
batch_points_arrow/encode_log_msg 357987 ns/iter (± 2776) 355756 ns/iter (± 1583) 1.01
batch_points_arrow/encode_total 703875 ns/iter (± 4411) 710250 ns/iter (± 2139) 0.99
batch_points_arrow/decode_log_msg 350549 ns/iter (± 1423) 349188 ns/iter (± 1908) 1.00
batch_points_arrow/decode_message_bundles 2069 ns/iter (± 10) 2102 ns/iter (± 19) 0.98
batch_points_arrow/decode_total 357653 ns/iter (± 1012) 357612 ns/iter (± 1643) 1.00
arrow_mono_points/insert 6180012468 ns/iter (± 17070432) 6096274253 ns/iter (± 32005044) 1.01
arrow_mono_points/query 1751430 ns/iter (± 13164) 1769668 ns/iter (± 15200) 0.99
arrow_batch_points/insert 2640954 ns/iter (± 28355) 2658575 ns/iter (± 14877) 0.99
arrow_batch_points/query 16222 ns/iter (± 120) 16178 ns/iter (± 54) 1.00
arrow_batch_vecs/insert 41707 ns/iter (± 360) 42015 ns/iter (± 279) 0.99
arrow_batch_vecs/query 385432 ns/iter (± 8295) 385309 ns/iter (± 4631) 1.00
tuid/Tuid::random 34 ns/iter (± 0) 35 ns/iter (± 0) 0.97

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.