From f3e1ac8dbe1798bc808894628ad78a29da39ceb1 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 4 Dec 2020 12:14:07 +0000 Subject: [PATCH] Defensive code to prevent lookup of stale parent board. Fixes https://gitlab.com/kicad/code/kicad/issues/6618 --- pcbnew/footprint.cpp | 5 +---- pcbnew/plugins/eagle/eagle_plugin.cpp | 4 +++- pcbnew/plugins/geda/gpcb_plugin.cpp | 10 +++++++++- pcbnew/plugins/kicad/kicad_plugin.cpp | 10 +++++++++- pcbnew/plugins/legacy/legacy_plugin.cpp | 4 +++- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index b10f3b9765..d60f027f0f 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -155,14 +155,11 @@ FOOTPRINT::FOOTPRINT( const FOOTPRINT& aFootprint ) : m_3D_Drawings = aFootprint.m_3D_Drawings; m_doc = aFootprint.m_doc; - m_keywords = aFootprint.m_keywords; + m_keywords = aFootprint.m_keywords; m_properties = aFootprint.m_properties; m_arflag = 0; - // Ensure auxiliary data is up to date - CalculateBoundingBox(); - m_initial_comments = aFootprint.m_initial_comments ? new wxArrayString( *aFootprint.m_initial_comments ) : nullptr; } diff --git a/pcbnew/plugins/eagle/eagle_plugin.cpp b/pcbnew/plugins/eagle/eagle_plugin.cpp index 5d3cc50f6e..daa00b25da 100644 --- a/pcbnew/plugins/eagle/eagle_plugin.cpp +++ b/pcbnew/plugins/eagle/eagle_plugin.cpp @@ -2847,7 +2847,9 @@ FOOTPRINT* EAGLE_PLUGIN::FootprintLoad( const wxString& aLibraryPath, return NULL; // Return a copy of the template - return (FOOTPRINT*) it->second->Duplicate(); + FOOTPRINT* copy = (FOOTPRINT*) it->second->Duplicate(); + copy->SetParent( nullptr ); + return copy; } diff --git a/pcbnew/plugins/geda/gpcb_plugin.cpp b/pcbnew/plugins/geda/gpcb_plugin.cpp index 805138f01a..69be484b5a 100644 --- a/pcbnew/plugins/geda/gpcb_plugin.cpp +++ b/pcbnew/plugins/geda/gpcb_plugin.cpp @@ -936,7 +936,15 @@ FOOTPRINT* GPCB_PLUGIN::FootprintLoad( const wxString& aLibraryPath, const PROPERTIES* aProperties ) { const FOOTPRINT* footprint = getFootprint( aLibraryPath, aFootprintName, aProperties, true ); - return footprint ? (FOOTPRINT*) footprint->Duplicate() : nullptr; + + if( footprint ) + { + FOOTPRINT* copy = (FOOTPRINT*) footprint->Duplicate(); + copy->SetParent( nullptr ); + return copy; + } + + return nullptr; } diff --git a/pcbnew/plugins/kicad/kicad_plugin.cpp b/pcbnew/plugins/kicad/kicad_plugin.cpp index 5ddc2c9cb4..78d65b26b0 100644 --- a/pcbnew/plugins/kicad/kicad_plugin.cpp +++ b/pcbnew/plugins/kicad/kicad_plugin.cpp @@ -2238,7 +2238,15 @@ FOOTPRINT* PCB_IO::FootprintLoad( const wxString& aLibraryPath, const wxString& const PROPERTIES* aProperties ) { const FOOTPRINT* footprint = getFootprint( aLibraryPath, aFootprintName, aProperties, true ); - return footprint ? (FOOTPRINT*) footprint->Duplicate() : nullptr; + + if( footprint ) + { + FOOTPRINT* copy = (FOOTPRINT*) footprint->Duplicate(); + copy->SetParent( nullptr ); + return copy; + } + + return nullptr; } diff --git a/pcbnew/plugins/legacy/legacy_plugin.cpp b/pcbnew/plugins/legacy/legacy_plugin.cpp index 8068182a52..4e9dbed624 100644 --- a/pcbnew/plugins/legacy/legacy_plugin.cpp +++ b/pcbnew/plugins/legacy/legacy_plugin.cpp @@ -3325,7 +3325,9 @@ FOOTPRINT* LEGACY_PLUGIN::FootprintLoad( const wxString& aLibraryPath, } // Return copy of already loaded FOOTPRINT - return (FOOTPRINT*) it->second->Duplicate(); + FOOTPRINT* copy = (FOOTPRINT*) it->second->Duplicate(); + copy->SetParent( nullptr ); + return copy; }