Don't leave dangling net pointers on PCB_SHAPEs.

Also makes it harder for this type of error to occur in
future.
This commit is contained in:
Jeff Young 2024-02-20 15:26:27 +00:00
parent 2e97d5d7cc
commit 012b32e989
1 changed files with 7 additions and 24 deletions

View File

@ -967,31 +967,16 @@ void BOARD::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aRemoveMode )
{ {
case PCB_NETINFO_T: case PCB_NETINFO_T:
{ {
NETINFO_ITEM* item = static_cast<NETINFO_ITEM*>( aBoardItem ); NETINFO_ITEM* netItem = static_cast<NETINFO_ITEM*>( aBoardItem );
NETINFO_ITEM* unconnected = m_NetInfo.GetNetItem( NETINFO_LIST::UNCONNECTED ); NETINFO_ITEM* unconnected = m_NetInfo.GetNetItem( NETINFO_LIST::UNCONNECTED );
for( FOOTPRINT* fp : m_footprints ) for( BOARD_CONNECTED_ITEM* boardItem : AllConnectedItems() )
{ {
for( PAD* pad : fp->Pads() ) if( boardItem->GetNet() == netItem )
{ boardItem->SetNet( unconnected );
if( pad->GetNet() == item )
pad->SetNet( unconnected );
}
} }
for( ZONE* zone : m_zones ) m_NetInfo.RemoveNet( netItem );
{
if( zone->GetNet() == item )
zone->SetNet( unconnected );
}
for( PCB_TRACK* track : m_tracks )
{
if( track->GetNet() == item )
track->SetNet( unconnected );
}
m_NetInfo.RemoveNet( item );
break; break;
} }
@ -2271,10 +2256,8 @@ const std::vector<BOARD_CONNECTED_ITEM*> BOARD::AllConnectedItems()
for( BOARD_ITEM* item : Drawings() ) for( BOARD_ITEM* item : Drawings() )
{ {
if( item->Type() == PCB_SHAPE_T ) if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
{ items.push_back( bci );
items.push_back( dynamic_cast<PCB_SHAPE*>( item ) );
}
} }
return items; return items;