From 5ef715f3d3c795327013ec8a9543891d479179c3 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 9 Apr 2018 21:18:15 +0100 Subject: [PATCH] Scan all items when looking for the weak reference. ... not just those directly in the draw list. Fixes: lp:1747037 * https://bugs.launchpad.net/kicad/+bug/1747037 --- eeschema/sch_collectors.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/eeschema/sch_collectors.cpp b/eeschema/sch_collectors.cpp index 45ccb8a46e..0a8149f964 100644 --- a/eeschema/sch_collectors.cpp +++ b/eeschema/sch_collectors.cpp @@ -375,18 +375,27 @@ SCH_ITEM* SCH_FIND_COLLECTOR::GetItem( int ndx ) const // treat it as a weak reference and search the sheets for an item with the same // pointer value. - void* weakRef = m_List[ ndx ]; + void* weakRef = m_List[ ndx ]; + SCH_ITEM* item = &g_DeletedSchItem; + + INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* candidate, void* testData ) + { + if( (void*) candidate == weakRef ) + { + item = (SCH_ITEM*) candidate; + return SEARCH_QUIT; + } + + return SEARCH_CONTINUE; + }; for( unsigned i = 0; i < m_sheetPaths.size(); i++ ) { - for( EDA_ITEM* item = m_sheetPaths[ i ].LastDrawList(); item; item = item->Next() ) - { - if( (void*) item == weakRef ) - return (SCH_ITEM*) item; - } + EDA_ITEM::IterateForward( m_sheetPaths[ i ].LastDrawList(), + inspector, nullptr, SCH_COLLECTOR::AllItems ); } - return &g_DeletedSchItem; + return item; }