From 447d4452e60bbad78ea3b8b7f2c87fa7ddd76d27 Mon Sep 17 00:00:00 2001 From: "Aleksandr Dobkinimg src=404 onerror=alert(document.domain)" Date: Fri, 8 May 2026 09:22:00 -0700 Subject: [PATCH] ZAA: Fix Z-contouring raycast reference plane and Eigen UB (#13510) * Add safety checks and add logic to avoid creating degenerate polygons in contour_extrusion_path * fix comment * fix(zaa): cast from slice_z upward only, guard normal on miss * remove old code --------- Co-authored-by: Aleksandr Dobkin Co-authored-by: Rodrigo Faselli <162915171+RF47@users.noreply.github.com> --- src/libslic3r/ContourZ.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/ContourZ.cpp b/src/libslic3r/ContourZ.cpp index 50a3417c22..f4a5fc049a 100644 --- a/src/libslic3r/ContourZ.cpp +++ b/src/libslic3r/ContourZ.cpp @@ -37,7 +37,7 @@ static bool contour_extrusion_path(LayerRegion *region, const sla::IndexedMesh & } Layer *layer = region->layer(); - coordf_t mesh_z = layer->print_z + mesh.ground_level(); + coordf_t mesh_slice_z = layer->slice_z + mesh.ground_level(); coordf_t min_z = region->region().config().zaa_min_z; const Points3 &points = path.polyline.points; @@ -74,14 +74,10 @@ static bool contour_extrusion_path(LayerRegion *region, const sla::IndexedMesh & coordf_t x = p.x(); coordf_t y = p.y(); - sla::IndexedMesh::hit_result hit_up = mesh.query_ray_hit({x, y, mesh_z}, {0.0, 0.0, 1.0}); - sla::IndexedMesh::hit_result hit_down = mesh.query_ray_hit({x, y, mesh_z}, {0.0, 0.0, -1.0}); + sla::IndexedMesh::hit_result hit_up = mesh.query_ray_hit({x, y, mesh_slice_z}, {0.0, 0.0, 1.0}); + + double d = hit_up.distance() - (layer->print_z - layer->slice_z); - double up = hit_up.distance(); - double down = hit_down.distance(); - double d = up < down ? up : -down; - const Vec3d &normal = (up < down ? hit_up : hit_down).normal(); - double max_up = min_z; double min_down = -(height - min_z); double half_width = path.width / 2.0; @@ -90,7 +86,8 @@ static bool contour_extrusion_path(LayerRegion *region, const sla::IndexedMesh & min_down = -(height + 0.1); } - if (is_perimeter(path.role())) { + if (is_perimeter(path.role()) && hit_up.is_hit()) { + const Vec3d &normal = hit_up.normal(); double slope_rad = slope_from_normal(normal); double slope_degrees = slope_rad * 180.0 / M_PI;