From aebbe807f2d7b9d4c7ed001638e58210b25dedfa Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 10 Mar 2023 21:01:39 +0800 Subject: [PATCH] FIX: update_sequential_clearance may crash due to clipper's bug offset may give empty results. The previous patch solved the issue that the studio crashes immediately when selecting by-object printing. This patch solves the issue that the studio crashes when moving objects with mouse after selecting by-object printing. Jira: STUDIO-2452 Change-Id: Iacd69e67386b0750f24e5af2799ff9c0da130e88 (cherry picked from commit 8ea4379d0b6d61e91bd6704e4b1e8309cb42b924) --- src/slic3r/GUI/GLCanvas3D.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 7756d3680..b0f9b5484 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -4964,17 +4964,19 @@ void GLCanvas3D::update_sequential_clearance() for (size_t i = 0; i < m_model->objects.size(); ++i) { ModelObject* model_object = m_model->objects[i]; ModelInstance* model_instance0 = model_object->instances.front(); - Polygon hull_2d = offset(model_object->convex_hull_2d(Geometry::assemble_transform({ 0.0, 0.0, model_instance0->get_offset().z() }, model_instance0->get_rotation(), + auto tmp = offset(model_object->convex_hull_2d(Geometry::assemble_transform({ 0.0, 0.0, model_instance0->get_offset().z() }, model_instance0->get_rotation(), model_instance0->get_scaling_factor(), model_instance0->get_mirror())), // Shrink the extruder_clearance_radius a tiny bit, so that if the object arrangement algorithm placed the objects // exactly by satisfying the extruder_clearance_radius, this test will not trigger collision. shrink_factor, - jtRound, mitter_limit).front(); - - Pointf3s& cache_hull_2d = m_sequential_print_clearance.m_hull_2d_cache.emplace_back(Pointf3s()); - cache_hull_2d.reserve(hull_2d.points.size()); - for (const Point& p : hull_2d.points) { - cache_hull_2d.emplace_back(unscale(p.x()), unscale(p.y()), 0.0); + jtRound, mitter_limit); + if (!tmp.empty()) { // tmp may be empty due to clipper's bug, see STUDIO-2452 + Polygon hull_2d = tmp.front(); + Pointf3s& cache_hull_2d = m_sequential_print_clearance.m_hull_2d_cache.emplace_back(Pointf3s()); + cache_hull_2d.reserve(hull_2d.points.size()); + for (const Point& p : hull_2d.points) { + cache_hull_2d.emplace_back(unscale(p.x()), unscale(p.y()), 0.0); + } } } m_sequential_print_clearance_first_displacement = false;