From 7520a8b316fec6750836bf514bed68098b9ffb04 Mon Sep 17 00:00:00 2001 From: Yon Uriarte Date: Wed, 6 Mar 2024 18:48:49 +0000 Subject: [PATCH] Avoid updating max clearance while in dtor Max clearance is updated by IncrementTimeStamp(), which is called when in the FOOTPRINT dtor and ZONE dtor. This can cause issues when iterating over all footprints as the footprints may be delete-ed Fixes https://gitlab.com/kicad/code/kicad/issues/17269 --- pcbnew/board.cpp | 12 ++++++++---- pcbnew/board.h | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pcbnew/board.cpp b/pcbnew/board.cpp index bb405d71ab..51c3b4c717 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -80,7 +80,7 @@ BOARD::BOARD() : m_project( nullptr ), m_userUnits( EDA_UNITS::MILLIMETRES ), m_designSettings( new BOARD_DESIGN_SETTINGS( nullptr, "board.design_settings" ) ), - m_deleting( false ), + m_skipMaxClearanceCacheUpdate( false ), m_maxClearanceValue( 0 ), m_NetInfo( this ) { @@ -133,7 +133,7 @@ BOARD::BOARD() : BOARD::~BOARD() { - m_deleting = true; + m_skipMaxClearanceCacheUpdate = true; // Untangle group parents before doing any deleting for( PCB_GROUP* group : m_groups ) @@ -780,8 +780,8 @@ BOARD_DESIGN_SETTINGS& BOARD::GetDesignSettings() const void BOARD::UpdateMaxClearanceCache() { - // in destructor, useless work - if( m_deleting ) + // in destructor or otherwise reasonable to skip + if( m_skipMaxClearanceCacheUpdate ) return; int worstClearance = m_designSettings->GetBiggestClearanceValue(); @@ -1121,10 +1121,14 @@ void BOARD::DeleteMARKERs( bool aWarningsAndErrors, bool aExclusions ) void BOARD::DeleteAllFootprints() { + m_skipMaxClearanceCacheUpdate = true; + for( FOOTPRINT* footprint : m_footprints ) delete footprint; m_footprints.clear(); + m_skipMaxClearanceCacheUpdate = false; + UpdateMaxClearanceCache(); } diff --git a/pcbnew/board.h b/pcbnew/board.h index 93011a30ff..824a91d60e 100644 --- a/pcbnew/board.h +++ b/pcbnew/board.h @@ -1320,7 +1320,7 @@ private: */ bool m_legacyTeardrops = false; - bool m_deleting; // inside destructor + bool m_skipMaxClearanceCacheUpdate; int m_maxClearanceValue; // cached value NETINFO_LIST m_NetInfo; // net info list (name, design constraints...