Skip to content

Commit

Permalink
Fix crash/freeze when zooming out too far in a plot (#5737)
Browse files Browse the repository at this point in the history
### 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)
  • Loading branch information
emilk authored Apr 2, 2024
1 parent cd07140 commit d00aa27
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions crates/re_space_view_time_series/src/space_view_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,15 +400,15 @@ It can greatly improve performance (and readability) in such situations as it pr
.x_axis_formatter(move |time, _, _| {
format_time(
time_type,
time.value as i64 + time_offset,
(time.value as i64).saturating_add(time_offset),
time_zone_for_timestamps,
)
})
.y_axis_width(3) // in digits
.label_formatter(move |name, value| {
let name = if name.is_empty() { "y" } else { name };
let label = time_type.format(
(value.x as i64 + time_offset).into(),
((value.x as i64).saturating_add(time_offset)).into(),
time_zone_for_timestamps,
);

Expand Down Expand Up @@ -803,7 +803,12 @@ fn ns_grid_spacer(

let mut small_spacing_ns = 1;
while width_ns / (next_grid_tick_magnitude_ns(small_spacing_ns) as f64) > max_medium_lines {
small_spacing_ns = next_grid_tick_magnitude_ns(small_spacing_ns);
let next_ns = next_grid_tick_magnitude_ns(small_spacing_ns);
if small_spacing_ns < next_ns {
small_spacing_ns = next_ns;
} else {
break; // we've reached the max
}
}
let medium_spacing_ns = next_grid_tick_magnitude_ns(small_spacing_ns);
let big_spacing_ns = next_grid_tick_magnitude_ns(medium_spacing_ns);
Expand All @@ -828,7 +833,11 @@ fn ns_grid_spacer(
step_size: step_size as f64,
});

current_ns += small_spacing_ns;
if let Some(new_ns) = current_ns.checked_add(small_spacing_ns) {
current_ns = new_ns;
} else {
break;
};
}

marks
Expand Down

0 comments on commit d00aa27

Please sign in to comment.