Fix attempt to subtract with overflow panic in SAPRegion::update_after_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 <sebcrozet@dimforge.com>
This commit is contained in:
Di Saber
2024-06-23 16:26:08 -05:00
committed by GitHub
parent 5308a28435
commit a854de787f

View File

@@ -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;
}