diff --git a/libs/kimath/src/geometry/shape_line_chain.cpp b/libs/kimath/src/geometry/shape_line_chain.cpp index 97117f0269..e045a6a46b 100644 --- a/libs/kimath/src/geometry/shape_line_chain.cpp +++ b/libs/kimath/src/geometry/shape_line_chain.cpp @@ -1788,6 +1788,12 @@ SHAPE_LINE_CHAIN& SHAPE_LINE_CHAIN::Simplify( bool aRemoveColinear ) const VECTOR2I SHAPE_LINE_CHAIN::NearestPoint( const VECTOR2I& aP, bool aAllowInternalShapePoints ) const { + if( PointCount() == 0 ) + { + // The only right answer here is "don't crash". + return { 0, 0 }; + } + int min_d = INT_MAX; int nearest = 0; @@ -1839,6 +1845,12 @@ const VECTOR2I SHAPE_LINE_CHAIN::NearestPoint( const VECTOR2I& aP, const VECTOR2I SHAPE_LINE_CHAIN::NearestPoint( const SEG& aSeg, int& dist ) const { + if( PointCount() == 0 ) + { + // The only right answer here is "don't crash". + return { 0, 0 }; + } + int nearest = 0; dist = INT_MAX;