diff --git a/src/libslic3r/Line.cpp b/src/libslic3r/Line.cpp index 3a180f747..68a7449c7 100644 --- a/src/libslic3r/Line.cpp +++ b/src/libslic3r/Line.cpp @@ -29,7 +29,14 @@ bool Line::intersection_infinite(const Line &other, Point* point) const if (std::fabs(denom) < EPSILON) return false; double t1 = cross2(v12, v2) / denom; - *point = (a1 + t1 * v1).cast(); + Vec2d result = (a1 + t1 * v1); + if (result.x() > std::numeric_limits::max() || result.x() < std::numeric_limits::lowest() || + result.y() > std::numeric_limits::max() || result.y() < std::numeric_limits::lowest()) { + // Intersection has at least one of the coordinates much bigger (or smaller) than coord_t maximum value (or minimum). + // So it can not be stored into the Point without integer overflows. That could mean that input lines are parallel or near parallel. + return false; + } + *point = (result).cast(); return true; }