Catch panics in booleanops. There's a reproducible case in the LTN tool.

Remove when https://github.com/georust/geo/issues/913 fixed
This commit is contained in:
Dustin Carlino 2022-11-10 15:15:50 +00:00
parent c162cf438e
commit 717e97ccd1
2 changed files with 28 additions and 3 deletions

View File

@ -269,11 +269,27 @@ impl Polygon {
}
pub fn intersection(&self, other: &Self) -> Result<Vec<Self>> {
from_multi(self.to_geo().intersection(&other.to_geo()))
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
from_multi(self.to_geo().intersection(&other.to_geo()))
})) {
Ok(result) => result,
Err(err) => {
println!("BooleanOps crashed: {err:?}");
bail!("BooleanOps crashed: {err}");
}
}
}
pub fn difference(&self, other: &Self) -> Result<Vec<Self>> {
from_multi(self.to_geo().difference(&other.to_geo()))
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
from_multi(self.to_geo().difference(&other.to_geo()))
})) {
Ok(result) => result,
Err(err) => {
println!("BooleanOps crashed: {err:?}");
bail!("BooleanOps crashed: {err}");
}
}
}
pub fn convex_hull(list: Vec<Self>) -> Result<Self> {

View File

@ -238,7 +238,16 @@ impl Tessellation {
pub fn difference(&self, other: &Tessellation) -> Result<Vec<Polygon>> {
use geo::BooleanOps;
crate::polygon::from_multi(self.to_geo().difference(&other.to_geo()))
// TODO Remove after https://github.com/georust/geo/issues/913
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
crate::polygon::from_multi(self.to_geo().difference(&other.to_geo()))
})) {
Ok(result) => result,
Err(err) => {
println!("BooleanOps crashed: {err:?}");
bail!("BooleanOps crashed: {err}");
}
}
}
}