From 91569cf3cfcd09ca515b28f24ad3492a2c81944f Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 10 Oct 2024 08:54:13 +0200 Subject: [PATCH] PAD::FlipPrimitives(): ensure primitive parent member is up to date. Looks like the primitive parent member (the pad handling the primitive) is not always correct: it should be the pad.cpp. It can create crash (for instance in DRC) --- pcbnew/pad.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/pcbnew/pad.cpp b/pcbnew/pad.cpp index 3902c6d452..f08c4b8c64 100644 --- a/pcbnew/pad.cpp +++ b/pcbnew/pad.cpp @@ -936,7 +936,12 @@ void PAD::FlipPrimitives( FLIP_DIRECTION aFlipDirection ) [&]( PCB_LAYER_ID aLayer ) { for( std::shared_ptr& primitive : m_padStack.Primitives( aLayer ) ) + { + // Ensure the primitive parent is up to date. Flip uses GetBoard() that + // imply primitive parent is valid + primitive->SetParent(this); primitive->Flip( VECTOR2I( 0, 0 ), aFlipDirection ); + } } ); SetDirty(); @@ -1566,7 +1571,19 @@ BITMAPS PAD::GetMenuImage() const EDA_ITEM* PAD::Clone() const { - return new PAD( *this ); + PAD* cloned = new PAD( *this ); + + // Ensure the cloned primitives of the pad stack have the right parent + cloned->Padstack().ForEachUniqueLayer( + [&]( PCB_LAYER_ID aLayer ) + { + for( std::shared_ptr& primitive : cloned->m_padStack.Primitives( aLayer ) ) + { + primitive->SetParent(cloned); + } + } ); + + return cloned; } @@ -2203,7 +2220,6 @@ void PAD::doCheckPad( PCB_LAYER_ID aLayer, UNITS_PROVIDER* aUnitsProvider, const std::function& aErrorHandler ) const { - VECTOR2I drill_size = GetDrillSize(); wxString msg; VECTOR2I pad_size = GetSize( aLayer );