From 96e214739471ecf6a0d9fd0188e33eef92b7527c Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 6 May 2024 14:29:25 +0800 Subject: [PATCH] FIX: handle exception of dividing by zero in arranging jira: none Change-Id: I0d20464dbe81a80293539100f06d72dee456a27b (cherry picked from commit 94746ae9bf7f467243849570450567b4fdc78e3a) --- src/libslic3r/Arrange.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index 0ad7e45a1..b507a8530 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -927,8 +927,15 @@ template void remove_large_items(std::vector &items, Bin &&bin) template Radians min_area_boundingbox_rotation(const S &sh) { - return minAreaBoundingBox, boost::rational>(sh) - .angleToX(); + try { + return minAreaBoundingBox, boost::rational>(sh) + .angleToX(); + } + catch (const std::exception& e) { + // min_area_boundingbox_rotation may throw exception of dividing 0 if the object is already perfectly aligned to X + BOOST_LOG_TRIVIAL(error) << "arranging min_area_boundingbox_rotation fails, msg=" << e.what(); + return 0.0; + } } template