Skip to content

Commit d00aa27

Browse files
authored
Fix crash/freeze when zooming out too far in a plot (#5737)
### What We reach `i64::MAX` pretty quickly when zooming out on e.g. https://github.com/rerun-io/example-rs-github-stars. In debug builds this overflow would lead to a crash. In release I think it results in a freeze. ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using newly built examples: [app.rerun.io](https://app.rerun.io/pr/5737/index.html) * Using examples from latest `main` build: [app.rerun.io](https://app.rerun.io/pr/5737/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [app.rerun.io](https://app.rerun.io/pr/5737/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG * [x] If applicable, add a new check to the [release checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)! - [PR Build Summary](https://build.rerun.io/pr/5737) - [Docs preview](https://rerun.io/preview/62226e544f05221313db4abd9476f40caef73c9d/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/62226e544f05221313db4abd9476f40caef73c9d/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
1 parent cd07140 commit d00aa27

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

crates/re_space_view_time_series/src/space_view_class.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,15 @@ It can greatly improve performance (and readability) in such situations as it pr
400400
.x_axis_formatter(move |time, _, _| {
401401
format_time(
402402
time_type,
403-
time.value as i64 + time_offset,
403+
(time.value as i64).saturating_add(time_offset),
404404
time_zone_for_timestamps,
405405
)
406406
})
407407
.y_axis_width(3) // in digits
408408
.label_formatter(move |name, value| {
409409
let name = if name.is_empty() { "y" } else { name };
410410
let label = time_type.format(
411-
(value.x as i64 + time_offset).into(),
411+
((value.x as i64).saturating_add(time_offset)).into(),
412412
time_zone_for_timestamps,
413413
);
414414

@@ -803,7 +803,12 @@ fn ns_grid_spacer(
803803

804804
let mut small_spacing_ns = 1;
805805
while width_ns / (next_grid_tick_magnitude_ns(small_spacing_ns) as f64) > max_medium_lines {
806-
small_spacing_ns = next_grid_tick_magnitude_ns(small_spacing_ns);
806+
let next_ns = next_grid_tick_magnitude_ns(small_spacing_ns);
807+
if small_spacing_ns < next_ns {
808+
small_spacing_ns = next_ns;
809+
} else {
810+
break; // we've reached the max
811+
}
807812
}
808813
let medium_spacing_ns = next_grid_tick_magnitude_ns(small_spacing_ns);
809814
let big_spacing_ns = next_grid_tick_magnitude_ns(medium_spacing_ns);
@@ -828,7 +833,11 @@ fn ns_grid_spacer(
828833
step_size: step_size as f64,
829834
});
830835

831-
current_ns += small_spacing_ns;
836+
if let Some(new_ns) = current_ns.checked_add(small_spacing_ns) {
837+
current_ns = new_ns;
838+
} else {
839+
break;
840+
};
832841
}
833842

834843
marks

0 commit comments

Comments
 (0)