diff --git a/crates/prepress/src/flatten/geom.rs b/crates/prepress/src/flatten/geom.rs index c106bcd2ce..460c4a9bb2 100644 --- a/crates/prepress/src/flatten/geom.rs +++ b/crates/prepress/src/flatten/geom.rs @@ -412,9 +412,12 @@ impl Arrangement { } /// The contours of `top`'s faces for which `inside` holds. The contour walk returns an error when the -/// sweep left winding numbers that disagree around a point; that input is degenerate. +/// sweep left winding numbers that disagree around a point, and can still panic on other degenerate +/// input; either way that input is degenerate. fn contours(top: &Topology, inside: impl Fn(&Multi) -> bool) -> Result { - top.try_contours(inside).map_err(|_| GeomError::Degenerate) + std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| top.try_contours(inside))) + .map_err(|_| GeomError::Degenerate)? + .map_err(|_| GeomError::Degenerate) } /// A point as a map key (the arrangement's vertices are exact). diff --git a/crates/prepress/src/flatten/pdf.rs b/crates/prepress/src/flatten/pdf.rs index 845c114e3f..97263858b0 100644 --- a/crates/prepress/src/flatten/pdf.rs +++ b/crates/prepress/src/flatten/pdf.rs @@ -1272,21 +1272,24 @@ fn dash_pattern(path: &BezPath, dashes: &[f32]) -> Option> { } /// `path` filled by `rule`, as a path filled nonzero. An even-odd path is rebuilt from its -/// boundary; if that fails it is kept as it is. +/// boundary; if that fails or panics it is kept as it is. fn nonzero(path: &BezPath, rule: FillRule) -> BezPath { if rule == FillRule::NonZero { return path.clone(); } let closed = closed(path); - match linesweeper::binary_op(&closed, &BezPath::new(), linesweeper::FillRule::EvenOdd, linesweeper::BinaryOp::Union) { - Ok(contours) => { + let op = catch_unwind(AssertUnwindSafe(|| { + linesweeper::binary_op(&closed, &BezPath::new(), linesweeper::FillRule::EvenOdd, linesweeper::BinaryOp::Union) + })); + match op { + Ok(Ok(contours)) => { let mut out = BezPath::new(); for contour in contours.contours() { out.extend(contour.path.iter()); } out } - Err(_) => closed, + Ok(Err(_)) | Err(_) => closed, } }