From 507491030b9e270a90cb18014106dc14e3eaf610 Mon Sep 17 00:00:00 2001 From: dong10-admin <273634802@qq.com> Date: Sat, 14 Sep 2024 16:10:29 +0800 Subject: [PATCH] Fix the issue of avoiding excessive invalid computations that can cause the program to freeze when support is enabled and either support_bottom_distance or support_top_distance is very large. --- src/libslic3r/Support/TreeModelVolumes.cpp | 4 ++-- src/libslic3r/SupportMaterial.cpp | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/Support/TreeModelVolumes.cpp b/src/libslic3r/Support/TreeModelVolumes.cpp index d77400309b1..89cb15aaf8f 100644 --- a/src/libslic3r/Support/TreeModelVolumes.cpp +++ b/src/libslic3r/Support/TreeModelVolumes.cpp @@ -434,8 +434,8 @@ void TreeModelVolumes::calculateCollision(const coord_t radius, const LayerIndex if (const std::vector &outlines = m_layer_outlines[outline_idx].second; ! outlines.empty()) { const TreeSupportMeshGroupSettings &settings = m_layer_outlines[outline_idx].first; const coord_t layer_height = settings.layer_height; - const int z_distance_bottom_layers = int(round(double(settings.support_bottom_distance) / double(layer_height))); - const int z_distance_top_layers = int(round(double(settings.support_top_distance) / double(layer_height))); + const int z_distance_bottom_layers = int(round(double(settings.support_bottom_distance) / double(layer_height))) > 10 ? 10 : int(round(double(settings.support_bottom_distance) / double(layer_height))); + const int z_distance_top_layers = int(round(double(settings.support_top_distance) / double(layer_height))) > 10 ? 10 : int(round(double(settings.support_top_distance) / double(layer_height))); const coord_t xy_distance = outline_idx == m_current_outline_idx ? m_current_min_xy_dist : // technically this causes collision for the normal xy_distance to be larger by m_current_min_xy_dist_delta for all // not currently processing meshes as this delta will be added at request time. diff --git a/src/libslic3r/SupportMaterial.cpp b/src/libslic3r/SupportMaterial.cpp index b022607bf75..37b3f009e90 100644 --- a/src/libslic3r/SupportMaterial.cpp +++ b/src/libslic3r/SupportMaterial.cpp @@ -3322,16 +3322,26 @@ void PrintObjectSupportMaterial::trim_support_layers_by_object( // BOOST_LOG_TRIVIAL(trace) << "Support generator - trim_support_layers_by_object - trimmming non-empty layer " << idx_layer << " of " << nonempty_layers.size(); assert(! support_layer.polygons.empty() && support_layer.print_z >= m_slicing_params.raft_contact_top_z + EPSILON); // Find the overlapping object layers including the extra above / below gap. - coordf_t z_threshold = support_layer.bottom_print_z() - gap_extra_below + EPSILON; + double layer_height = 0.f; + if(object.layers().size() > 0){ + const Layer &object_layer = *object.layers()[0]; + layer_height = object_layer.height; + } + double g_e_below = gap_extra_below; + if(g_e_below > layer_height){ + g_e_below = layer_height; + } + coordf_t z_threshold = support_layer.bottom_print_z() - g_e_below + EPSILON; idx_object_layer_overlapping = Layer::idx_higher_or_equal( object.layers().begin(), object.layers().end(), idx_object_layer_overlapping, [z_threshold](const Layer *layer){ return layer->print_z >= z_threshold; }); // Collect all the object layers intersecting with this layer. Polygons polygons_trimming; size_t i = idx_object_layer_overlapping; + double d_gap_extra_above = gap_extra_above > 2*layer_height ? 2*layer_height : gap_extra_above; for (; i < object.layers().size(); ++ i) { const Layer &object_layer = *object.layers()[i]; - if (object_layer.bottom_z() > support_layer.print_z + gap_extra_above - EPSILON) + if (object_layer.bottom_z() > support_layer.print_z + d_gap_extra_above - EPSILON) break; bool is_overlap = is_layers_overlap(support_layer, object_layer);