From e86463a369183134df95d5bc7d7c8a6387117edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Mon, 11 Jul 2022 15:19:48 +0200 Subject: [PATCH] Fix of #8463 - Crash in SkeletalTrapezoidation::computePointCellRange() when a cell point didn't fit into Vec2i64 because it was too far away. --- src/libslic3r/Arachne/SkeletalTrapezoidation.cpp | 10 +++++++++- src/libslic3r/Arachne/utils/VoronoiUtils.cpp | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp b/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp index 2852d242c3..a6ed26904f 100644 --- a/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp +++ b/src/libslic3r/Arachne/SkeletalTrapezoidation.cpp @@ -293,7 +293,15 @@ bool SkeletalTrapezoidation::computePointCellRange(vd_t::cell_type& cell, Point& // Check if any point of the cell is inside or outside polygon // Copy whole cell into graph or not at all - + + // If the cell.incident_edge()->vertex0() is far away so much that it doesn't even fit into Vec2i64, then there is no way that it will be inside the input polygon. + assert(x <= double(std::numeric_limits::max()) && x >= std::numeric_limits::lowest()); + assert(y <= double(std::numeric_limits::max()) && y >= std::numeric_limits::lowest()); + if (const vd_t::vertex_type &vert = *cell.incident_edge()->vertex0(); + vert.x() >= double(std::numeric_limits::max()) || vert.x() <= double(std::numeric_limits::lowest()) || + vert.y() >= double(std::numeric_limits::max()) || vert.y() <= double(std::numeric_limits::lowest())) + return false; // Don't copy any part of this cell + const Point source_point = VoronoiUtils::getSourcePoint(cell, segments); const PolygonsPointIndex source_point_index = VoronoiUtils::getSourcePointIndex(cell, segments); Vec2i64 some_point = VoronoiUtils::p(cell.incident_edge()->vertex0()); diff --git a/src/libslic3r/Arachne/utils/VoronoiUtils.cpp b/src/libslic3r/Arachne/utils/VoronoiUtils.cpp index a0f219039b..3da556b470 100644 --- a/src/libslic3r/Arachne/utils/VoronoiUtils.cpp +++ b/src/libslic3r/Arachne/utils/VoronoiUtils.cpp @@ -17,7 +17,7 @@ Vec2i64 VoronoiUtils::p(const vd_t::vertex_type *node) const double y = node->y(); assert(x <= double(std::numeric_limits::max()) && x >= std::numeric_limits::lowest()); assert(y <= double(std::numeric_limits::max()) && y >= std::numeric_limits::lowest()); - return Vec2i64(int64_t(x + 0.5 - (x < 0)), int64_t(y + 0.5 - (y < 0))); // Round to the nearest integer coordinates. + return {int64_t(x + 0.5 - (x < 0)), int64_t(y + 0.5 - (y < 0))}; // Round to the nearest integer coordinates. } Point VoronoiUtils::getSourcePoint(const vd_t::cell_type& cell, const std::vector& segments)