From 08b93bd5ba52a5930a497b3860ee3f88a95d06f7 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 9 Jan 2021 16:46:00 +0100 Subject: [PATCH] FOOTPRINT::GetBoundingHull(): avoid returning a empty hull SHAPE_POLY_SET, when a footprint contains only texts. empty SHAPE_POLY_SET creates most of time issues (crashes for instance) when containing no data. Ensure the returned SHAPE_POLY_SET contains a minimal hull (a 0.04 mm square) Fixes #7026 https://gitlab.com/kicad/code/kicad/issues/7026 --- pcbnew/footprint.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index 9fe5f40fb2..e5a4d256a5 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2015 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2015 Wayne Stambaugh - * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -712,6 +712,22 @@ SHAPE_POLY_SET FOOTPRINT::GetBoundingHull() const } } + // If there are some graphic items, build the actual hull. + // However if no items, create a minimal polygon (can happen if a footprint + // is created with no item: it contains only 2 texts. + if( rawPolys.OutlineCount() == 0 ) + { + // generate a small dummy rectangular outline around the anchor + const int halfsize = Millimeter2iu( 0.02 ); + + rawPolys.NewOutline(); + // add a square: + rawPolys.Append( GetPosition().x - halfsize, GetPosition().y - halfsize ); + rawPolys.Append( GetPosition().x + halfsize, GetPosition().y - halfsize ); + rawPolys.Append( GetPosition().x + halfsize, GetPosition().y + halfsize ); + rawPolys.Append( GetPosition().x - halfsize, GetPosition().y + halfsize ); + } + std::vector convex_hull; BuildConvexHull( convex_hull, rawPolys );