Handle cleanup safely

Make sure that the connectivity has successfully completed before
attempting to merge segments.  Also avoids reaching into the shared_ptr
if we don't need to

Fixes https://gitlab.com/kicad/code/kicad/issues/13639
This commit is contained in:
Seth Hillbrand 2023-01-23 15:55:29 -08:00
parent e4a8b9e76d
commit e713a3eac2
5 changed files with 16 additions and 9 deletions

View File

@ -159,10 +159,13 @@ BOARD::~BOARD()
}
void BOARD::BuildConnectivity( PROGRESS_REPORTER* aReporter )
bool BOARD::BuildConnectivity( PROGRESS_REPORTER* aReporter )
{
GetConnectivity()->Build( this, aReporter );
if( !GetConnectivity()->Build( this, aReporter ) )
return false;
UpdateRatsnestExclusions();
return true;
}

View File

@ -428,7 +428,7 @@ public:
* especially the list of connected items, list of nets and rastnest data
* Needed after loading a board to have the connectivity database updated.
*/
void BuildConnectivity( PROGRESS_REPORTER* aReporter = nullptr );
bool BuildConnectivity( PROGRESS_REPORTER* aReporter = nullptr );
/**
* Delete all MARKERS from the board.

View File

@ -92,14 +92,14 @@ bool CONNECTIVITY_DATA::Update( BOARD_ITEM* aItem )
}
void CONNECTIVITY_DATA::Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter )
bool CONNECTIVITY_DATA::Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter )
{
aBoard->CacheTriangulation( aReporter );
std::unique_lock<KISPINLOCK> lock( m_lock, std::try_to_lock );
if( !lock )
return;
return false;
if( aReporter )
{
@ -135,6 +135,8 @@ void CONNECTIVITY_DATA::Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter )
aReporter->SetCurrentProgress( 1.0 );
aReporter->KeepRefreshing( false );
}
return true;
}

View File

@ -109,7 +109,7 @@ public:
* Function Build()
* Builds the connectivity database for the board aBoard.
*/
void Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter = nullptr );
bool Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter = nullptr );
/**
* Function Build()

View File

@ -478,7 +478,7 @@ void TRACKS_CLEANER::cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegment
removeItems( toRemove );
auto mergeSegments =
[&]( CN_CONNECTIVITY_ALGO* connectivity ) -> bool
[&]( std::shared_ptr<CN_CONNECTIVITY_ALGO> connectivity ) -> bool
{
for( PCB_TRACK* segment : m_brd->Tracks() )
{
@ -542,9 +542,11 @@ void TRACKS_CLEANER::cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegment
{
do
{
m_brd->BuildConnectivity();
while( !m_brd->BuildConnectivity() )
wxSafeYield();
m_connectedItemsCache.clear();
} while( mergeSegments( m_brd->GetConnectivity()->GetConnectivityAlgo().get() ) );
} while( mergeSegments( m_brd->GetConnectivity()->GetConnectivityAlgo() ) );
}
for( PCB_TRACK* track : m_brd->Tracks() )