Additional checks for item validity in CONNECTIVITY

Fixes: lp:1705455
* https://bugs.launchpad.net/kicad/+bug/1705455
This commit is contained in:
Maciej Suminski 2017-07-21 11:40:26 +02:00
parent c290e8a33b
commit 6f8f6f18f6
2 changed files with 28 additions and 9 deletions

View File

@ -330,9 +330,12 @@ const std::list<BOARD_CONNECTED_ITEM*> CONNECTIVITY_DATA::GetConnectedItems(
if( cl->Contains( aItem ) ) if( cl->Contains( aItem ) )
{ {
for( const auto item : *cl ) for( const auto item : *cl )
{
if( item->Valid() )
rv.push_back( item->Parent() ); rv.push_back( item->Parent() );
} }
} }
}
return rv; return rv;
} }
@ -346,7 +349,7 @@ const std::list<BOARD_CONNECTED_ITEM*> CONNECTIVITY_DATA::GetNetItems( int aNetC
m_connAlgo->ForEachItem( [&items, aNetCode, &aTypes] ( CN_ITEM* aItem ) m_connAlgo->ForEachItem( [&items, aNetCode, &aTypes] ( CN_ITEM* aItem )
{ {
if( aItem->Net() == aNetCode ) if( aItem->Valid() && aItem->Net() == aNetCode )
{ {
KICAD_T itemType = aItem->Parent()->Type(); KICAD_T itemType = aItem->Parent()->Type();
@ -462,6 +465,9 @@ unsigned int CONNECTIVITY_DATA::GetPadCount( int aNet ) const
for( auto pad : m_connAlgo->PadList() ) for( auto pad : m_connAlgo->PadList() )
{ {
if( !pad->Valid() )
continue;
auto dpad = static_cast<D_PAD*>( pad->Parent() ); auto dpad = static_cast<D_PAD*>( pad->Parent() );
if( aNet < 0 || aNet == dpad->GetNetCode() ) if( aNet < 0 || aNet == dpad->GetNetCode() )
@ -508,7 +514,7 @@ const std::vector<VECTOR2I> CONNECTIVITY_DATA::NearestUnconnectedTargets(
{ {
for( auto item : *cl ) for( auto item : *cl )
{ {
if( item->Parent()->GetNetCode() == refNet if( item->Valid() && item->Parent()->GetNetCode() == refNet
&& item->Parent()->Type() != PCB_ZONE_AREA_T ) && item->Parent()->Type() != PCB_ZONE_AREA_T )
{ {
for( auto anchor : item->Anchors() ) for( auto anchor : item->Anchors() )
@ -565,7 +571,7 @@ const std::vector<BOARD_CONNECTED_ITEM*> CONNECTIVITY_DATA::GetConnectedItems(
{ {
for( int i = 0; aTypes[i] > 0; i++ ) for( int i = 0; aTypes[i] > 0; i++ )
{ {
if( cnItem->Parent()->Type() == aTypes[i] ) if( cnItem->Valid() && cnItem->Parent()->Type() == aTypes[i] )
{ {
rv.push_back( cnItem->Parent() ); rv.push_back( cnItem->Parent() );
break; break;

View File

@ -61,7 +61,7 @@ CN_CLUSTER::~CN_CLUSTER()
wxString CN_CLUSTER::OriginNetName() const wxString CN_CLUSTER::OriginNetName() const
{ {
if( !m_originPad ) if( !m_originPad || !m_originPad->Valid() )
return "<none>"; return "<none>";
else else
return m_originPad->Parent()->GetNetname(); return m_originPad->Parent()->GetNetname();
@ -78,7 +78,7 @@ bool CN_CLUSTER::Contains( const BOARD_CONNECTED_ITEM* aItem )
{ {
for( auto item : m_items ) for( auto item : m_items )
{ {
if( item->Parent() == aItem ) if( item->Valid() && item->Parent() == aItem )
return true; return true;
} }
@ -766,7 +766,7 @@ void CN_CONNECTIVITY_ALGO::propagateConnections()
{ {
if( item->CanChangeNet() ) if( item->CanChangeNet() )
{ {
if( item->Parent()->GetNetCode() != cluster->OriginNet() ) if( item->Valid() && item->Parent()->GetNetCode() != cluster->OriginNet() )
{ {
MarkNetAsDirty( item->Parent()->GetNetCode() ); MarkNetAsDirty( item->Parent()->GetNetCode() );
MarkNetAsDirty( cluster->OriginNet() ); MarkNetAsDirty( cluster->OriginNet() );
@ -850,12 +850,18 @@ void CN_CONNECTIVITY_ALGO::MarkNetAsDirty( int aNet )
int CN_ITEM::AnchorCount() const int CN_ITEM::AnchorCount() const
{ {
if( !m_valid )
return 0;
return m_parent->Type() == PCB_TRACE_T ? 2 : 1; return m_parent->Type() == PCB_TRACE_T ? 2 : 1;
} }
const VECTOR2I CN_ITEM::GetAnchor( int n ) const const VECTOR2I CN_ITEM::GetAnchor( int n ) const
{ {
if( !m_valid )
return VECTOR2I();
switch( m_parent->Type() ) switch( m_parent->Type() )
{ {
case PCB_PAD_T: case PCB_PAD_T:
@ -882,6 +888,9 @@ const VECTOR2I CN_ITEM::GetAnchor( int n ) const
int CN_ZONE::AnchorCount() const int CN_ZONE::AnchorCount() const
{ {
if( !Valid() )
return 0;
const auto zone = static_cast<const ZONE_CONTAINER*>( Parent() ); const auto zone = static_cast<const ZONE_CONTAINER*>( Parent() );
const auto& outline = zone->GetFilledPolysList().COutline( m_subpolyIndex ); const auto& outline = zone->GetFilledPolysList().COutline( m_subpolyIndex );
@ -891,6 +900,9 @@ int CN_ZONE::AnchorCount() const
const VECTOR2I CN_ZONE::GetAnchor( int n ) const const VECTOR2I CN_ZONE::GetAnchor( int n ) const
{ {
if( !Valid() )
return VECTOR2I();
const auto zone = static_cast<const ZONE_CONTAINER*> ( Parent() ); const auto zone = static_cast<const ZONE_CONTAINER*> ( Parent() );
const auto& outline = zone->GetFilledPolysList().COutline( m_subpolyIndex ); const auto& outline = zone->GetFilledPolysList().COutline( m_subpolyIndex );
@ -900,7 +912,7 @@ const VECTOR2I CN_ZONE::GetAnchor( int n ) const
int CN_ITEM::Net() const int CN_ITEM::Net() const
{ {
if( !m_parent ) if( !m_parent || !m_valid )
return -1; return -1;
return m_parent->GetNetCode(); return m_parent->GetNetCode();
@ -909,6 +921,7 @@ int CN_ITEM::Net() const
BOARD_CONNECTED_ITEM* CN_ANCHOR::Parent() const BOARD_CONNECTED_ITEM* CN_ANCHOR::Parent() const
{ {
assert( m_item->Valid() );
return m_item->Parent(); return m_item->Parent();
} }