Skip to content

Commit

Permalink
Fix attempt to subtract with overflow panic in `SAPRegion::update_a…
Browse files Browse the repository at this point in the history
…fter_subregion_removal()` (#663)

* Swap a regular subtraction for a saturating subtraction

* chore: display a debug message if the SAP reach an unexpected state regarding sub-proper proxies removal.

---------

Co-authored-by: Sébastien Crozet <[email protected]>
  • Loading branch information
DiSaber and sebcrozet authored Jun 23, 2024
1 parent 5308a28 commit a854de7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/geometry/broad_phase_multi_sap/sap_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,23 @@ impl SAPRegion {
pub fn update_after_subregion_removal(&mut self, proxies: &SAPProxies, layer_depth: i8) {
if self.needs_update_after_subregion_removal {
for axis in &mut self.axes {
self.subproper_proxy_count -= axis
let removed_count = axis
.delete_deleted_proxies_and_endpoints_after_subregion_removal(
proxies,
&mut self.existing_proxies,
layer_depth,
);

if removed_count > self.subproper_proxy_count {
log::debug!(
"Reached unexpected state: attempted to remove more sub-proper proxies than added (removing: {}, total: {}).",
removed_count,
self.subproper_proxy_count
);
self.subproper_proxy_count = 0;
} else {
self.subproper_proxy_count -= removed_count;
}
}
self.needs_update_after_subregion_removal = false;
}
Expand Down

0 comments on commit a854de7

Please sign in to comment.