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,7 +330,10 @@ const std::list<BOARD_CONNECTED_ITEM*> CONNECTIVITY_DATA::GetConnectedItems(
if( cl->Contains( aItem ) )
{
for( const auto item : *cl )
rv.push_back( item->Parent() );
{
if( item->Valid() )
rv.push_back( item->Parent() );
}
}
}
@ -346,7 +349,7 @@ const std::list<BOARD_CONNECTED_ITEM*> CONNECTIVITY_DATA::GetNetItems( int aNetC
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();
@ -406,7 +409,7 @@ const
{
for( auto connected : citem->ConnectedItems() )
{
if( connected->Valid() && ( connected->Parent()->Type() == PCB_TRACE_T || connected->Parent()->Type() == PCB_VIA_T ) )
if( connected->Valid() && ( connected->Parent()->Type() == PCB_TRACE_T || connected->Parent()->Type() == PCB_VIA_T ) )
tracks.insert( static_cast<TRACK*> ( connected->Parent() ) );
}
}
@ -462,6 +465,9 @@ unsigned int CONNECTIVITY_DATA::GetPadCount( int aNet ) const
for( auto pad : m_connAlgo->PadList() )
{
if( !pad->Valid() )
continue;
auto dpad = static_cast<D_PAD*>( pad->Parent() );
if( aNet < 0 || aNet == dpad->GetNetCode() )
@ -508,7 +514,7 @@ const std::vector<VECTOR2I> CONNECTIVITY_DATA::NearestUnconnectedTargets(
{
for( auto item : *cl )
{
if( item->Parent()->GetNetCode() == refNet
if( item->Valid() && item->Parent()->GetNetCode() == refNet
&& item->Parent()->Type() != PCB_ZONE_AREA_T )
{
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++ )
{
if( cnItem->Parent()->Type() == aTypes[i] )
if( cnItem->Valid() && cnItem->Parent()->Type() == aTypes[i] )
{
rv.push_back( cnItem->Parent() );
break;

View File

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