diff --git a/pcbnew/router/pns_line_placer.cpp b/pcbnew/router/pns_line_placer.cpp index 9013f604ff..1b049b479d 100644 --- a/pcbnew/router/pns_line_placer.cpp +++ b/pcbnew/router/pns_line_placer.cpp @@ -1006,22 +1006,25 @@ bool LINE_PLACER::FixRoute( const VECTOR2I& aP, ITEM* aEndItem ) else lastV = std::max( 1, l.SegmentCount() - 1 ); - SEGMENT* lastSeg = NULL; + SEGMENT* lastSeg = nullptr; for( int i = 0; i < lastV; i++ ) { const SEG& s = pl.CSegment( i ); - std::unique_ptr< SEGMENT > seg( new SEGMENT( s, m_currentNet ) ); + lastSeg = new SEGMENT( s, m_currentNet ); + std::unique_ptr< SEGMENT > seg( lastSeg ); seg->SetWidth( pl.Width() ); seg->SetLayer( m_currentLayer ); - lastSeg = seg.get(); - m_lastNode->Add( std::move( seg ) ); + if( ! m_lastNode->Add( std::move( seg ) ) ) + { + lastSeg = nullptr; + } } if( pl.EndsWithVia() ) m_lastNode->Add( Clone( pl.Via() ) ); - if( realEnd ) + if( realEnd && lastSeg ) simplifyNewLine( m_lastNode, lastSeg ); Router()->CommitRouting( m_lastNode ); diff --git a/pcbnew/router/pns_node.cpp b/pcbnew/router/pns_node.cpp index c09a1647d1..cc4be88652 100644 --- a/pcbnew/router/pns_node.cpp +++ b/pcbnew/router/pns_node.cpp @@ -591,19 +591,21 @@ void NODE::addSegment( SEGMENT* aSeg ) m_index->Add( aSeg ); } -void NODE::Add( std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant ) +bool NODE::Add( std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant ) { if( aSegment->Seg().A == aSegment->Seg().B ) { wxLogTrace( "PNS", "attempting to add a segment with same end coordinates, ignoring." ); - return; + return false; } if( !aAllowRedundant && findRedundantSegment( aSegment.get() ) ) - return; + return false; aSegment->SetOwner( this ); addSegment( aSegment.release() ); + + return true; } void NODE::Add( std::unique_ptr< ITEM > aItem, bool aAllowRedundant ) diff --git a/pcbnew/router/pns_node.h b/pcbnew/router/pns_node.h index decec562b4..b7278fa818 100644 --- a/pcbnew/router/pns_node.h +++ b/pcbnew/router/pns_node.h @@ -272,9 +272,10 @@ public: * Adds an item to the current node. * @param aSegment item to add * @param aAllowRedundant if true, duplicate items are allowed (e.g. a segment or via + * @return true if added * at the same coordinates as an existing one) */ - void Add( std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant = false ); + bool Add( std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant = false ); void Add( std::unique_ptr< SOLID > aSolid ); void Add( std::unique_ptr< VIA > aVia );