From 2a27471363136a21040dbd7d28b9e5d35f42c5e9 Mon Sep 17 00:00:00 2001 From: 0HyperCube <78500760+0HyperCube@users.noreply.github.com> Date: Mon, 9 Jan 2023 02:25:06 +0000 Subject: [PATCH] Fix boolean crash with self intersecting shape (#952) --- document-legacy/src/boolean_ops.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/document-legacy/src/boolean_ops.rs b/document-legacy/src/boolean_ops.rs index c3e2cd65..7f70d405 100644 --- a/document-legacy/src/boolean_ops.rs +++ b/document-legacy/src/boolean_ops.rs @@ -25,6 +25,7 @@ pub enum BooleanOperationError { NoIntersections, NothingDone, // Not necessarily an error DirectionUndefined, + NoResult, Unexpected, // For debugging, when complete nothing should be unexpected } @@ -492,9 +493,13 @@ pub fn composite_boolean_operation(mut select: BooleanOperation, shapes: &mut Ve match partial_union { Ok(temp_union) => { // The result of a successful union will be exactly one shape - shapes.push(RefCell::new(temp_union.into_iter().next().unwrap())); - shapes.swap_remove(subject_idx); - shapes.swap_remove(shape_idx); + if let Some(result) = temp_union.into_iter().next() { + shapes.push(RefCell::new(result)); + shapes.swap_remove(subject_idx); + shapes.swap_remove(shape_idx); + } else { + return Err(BooleanOperationError::NoResult); + } } Err(BooleanOperationError::NothingDone) => shape_idx += 1, Err(err) => return Err(err),