From e4f6315da0b61a6f4e3a0fb0af5ddcd81e640a67 Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 10 Mar 2023 21:15:26 +0800 Subject: [PATCH] FIX: update_sequential_clearance may crash due to clipper's bug m_hull_2d_cache must be set since later on we'll use its point number, which is a very large number when not inited. This will cause a fatal out-of-memory error. Jira: STUDIO-2452 Change-Id: I9b397a53bdcdf555eccf745f1b96786010ebe309 (cherry picked from commit 6802be53709649e75a1562d29e14559c766d427b) --- src/slic3r/GUI/GLCanvas3D.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index b0f9b5484..b44c002c0 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -4964,20 +4964,20 @@ 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(); - 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())), + Polygon hull_no_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())); + auto tmp = offset(hull_no_offset, // 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); - 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); - } - } + Polygon hull_2d = !tmp.empty() ? tmp.front() : hull_no_offset;// tmp may be empty due to clipper's bug, see STUDIO-2452 + + 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; }