From 026685ee48909cea2bddd06d0efb7d49dfb73acd Mon Sep 17 00:00:00 2001 From: JamesJ <13408010-JamesJCode@users.noreply.gitlab.com> Date: Sat, 6 Apr 2024 18:44:23 +0100 Subject: [PATCH] Check a SHAPE_POLY_SET outline exists before attempting to get it by index Fixes https://gitlab.com/kicad/code/kicad/-/issues/17687 --- libs/kimath/src/geometry/shape.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libs/kimath/src/geometry/shape.cpp b/libs/kimath/src/geometry/shape.cpp index 7d9902d63e..768709594d 100644 --- a/libs/kimath/src/geometry/shape.cpp +++ b/libs/kimath/src/geometry/shape.cpp @@ -62,14 +62,26 @@ int SHAPE::GetClearance( const SHAPE* aOther ) const /// Triangles check three vertices each but for the outline, we only need one. /// These are also fractured, so we don't need to worry about holes if( Type() == SHAPE_TYPE::SH_POLY_SET ) - a_shapes.push_back( &static_cast( this )->COutline( 0 ) ); + { + const SHAPE_POLY_SET* polySet = static_cast( this ); + if( polySet->OutlineCount() > 0 ) + a_shapes.push_back( &polySet->COutline( 0 ) ); + } else + { GetIndexableSubshapes( a_shapes ); + } if( aOther->Type() == SHAPE_TYPE::SH_POLY_SET ) - b_shapes.push_back( &static_cast( aOther )->COutline( 0 ) ); + { + const SHAPE_POLY_SET* polySet = static_cast( aOther ); + if( polySet->OutlineCount() > 0 ) + b_shapes.push_back( &polySet->COutline( 0 ) ); + } else + { aOther->GetIndexableSubshapes( b_shapes ); + } if( GetIndexableSubshapeCount() == 0 ) a_shapes.push_back( this );