7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-11 00:30:01 +00:00

BOARD::GetBoardPolygonOutlines(): Protect against malformed NPTH pads

In some cases, when modifying a pad (SMD -> NPTH from properties panel, one
can generate a NPTH pad with a zero sized hole. Pcbnew can crash with such a pad,
especially if the 3D viewer is shown during modification.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18585
This commit is contained in:
jean-pierre charras 2024-08-22 11:10:05 +02:00
parent e0fc7b2b88
commit 9973f1b306

View File

@ -2498,18 +2498,21 @@ bool BOARD::GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines,
SHAPE_POLY_SET hole;
pad->TransformHoleToPolygon( hole, 0, GetDesignSettings().m_MaxError, ERROR_INSIDE );
// Add this pad hole to the main outline
// But we can have more than one main outline (i.e. more than one board), so
// search the right main outline i.e. the outline that contains the pad hole
SHAPE_LINE_CHAIN& pad_hole = hole.Outline( 0 );
const VECTOR2I holePt = pad_hole.CPoint( 0 );
for( int jj = 0; jj < aOutlines.OutlineCount(); ++jj )
if( hole.OutlineCount() > 0 ) // can be not the case for malformed NPTH holes
{
if( aOutlines.Outline( jj ).PointInside( holePt ) )
// Add this pad hole to the main outline
// But we can have more than one main outline (i.e. more than one board), so
// search the right main outline i.e. the outline that contains the pad hole
SHAPE_LINE_CHAIN& pad_hole = hole.Outline( 0 );
const VECTOR2I holePt = pad_hole.CPoint( 0 );
for( int jj = 0; jj < aOutlines.OutlineCount(); ++jj )
{
aOutlines.AddHole( pad_hole, jj );
break;
if( aOutlines.Outline( jj ).PointInside( holePt ) )
{
aOutlines.AddHole( pad_hole, jj );
break;
}
}
}
}