From 0faad370f95dcead5dff9eab442aad23ad9f75e1 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 18 Sep 2023 18:02:41 -0700 Subject: [PATCH] Fix some stale pointers in incremental updates Shared pointers contained stale references to the temporary graph. When merging, we need to ensure all references are updated to the final graph (cherry picked from commit b52c43b9337680472c46f3cc3d377a9e46465120) --- eeschema/connection_graph.cpp | 19 +++++++++++++------ eeschema/sch_item.cpp | 5 +++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index c4b2fb6874..f9ed9323e5 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -516,7 +516,12 @@ void CONNECTION_GRAPH::Merge( CONNECTION_GRAPH& aGraph ) std::back_inserter( m_subgraphs ) ); for( CONNECTION_SUBGRAPH* sg : aGraph.m_subgraphs ) + { + if( sg->m_driver_connection ) + sg->m_driver_connection->SetGraph( this ); + sg->m_graph = this; + } std::copy( aGraph.m_driver_subgraphs.begin(), aGraph.m_driver_subgraphs.end(), @@ -553,6 +558,7 @@ void CONNECTION_GRAPH::Merge( CONNECTION_GRAPH& aGraph ) m_last_bus_code = std::max( m_last_bus_code, aGraph.m_last_bus_code ); m_last_net_code = std::max( m_last_net_code, aGraph.m_last_net_code ); m_last_subgraph_code = std::max( m_last_subgraph_code, aGraph.m_last_subgraph_code ); + } @@ -770,23 +776,23 @@ void CONNECTION_GRAPH::removeSubgraphs( std::set& aSubgrap { auto it = std::lower_bound( m_driver_subgraphs.begin(), m_driver_subgraphs.end(), sg ); - if( it != m_driver_subgraphs.end() ) - m_driver_subgraphs.erase( it ); + while( it != m_driver_subgraphs.end() && *it == sg ) + it = m_driver_subgraphs.erase( it ); } { auto it = std::lower_bound( m_subgraphs.begin(), m_subgraphs.end(), sg ); - if( it != m_subgraphs.end() ) - m_subgraphs.erase( it ); + while( it != m_subgraphs.end() && *it == sg ) + it = m_subgraphs.erase( it ); } for( auto el : m_sheet_to_subgraphs_map ) { auto it = std::lower_bound( el.second.begin(), el.second.end(), sg ); - if( it != el.second.end() ) - el.second.erase( it ); + while( it != el.second.end() && *it == sg ) + it = el.second.erase( it ); } auto remove_sg = [sg]( auto it ) -> bool @@ -863,6 +869,7 @@ void CONNECTION_GRAPH::removeSubgraphs( std::set& aSubgrap for( CONNECTION_SUBGRAPH* sg : aSubgraphs ) { sg->m_code = -1; + sg->m_graph = nullptr; delete sg; } } diff --git a/eeschema/sch_item.cpp b/eeschema/sch_item.cpp index bb8aea1262..188bf022e6 100644 --- a/eeschema/sch_item.cpp +++ b/eeschema/sch_item.cpp @@ -167,7 +167,12 @@ SCH_CONNECTION* SCH_ITEM::Connection( const SCH_SHEET_PATH* aSheet ) const void SCH_ITEM::SetConnectionGraph( CONNECTION_GRAPH* aGraph ) { for( auto& [path, conn] : m_connection_map ) + { conn->SetGraph( aGraph ); + + for( auto& member : conn->AllMembers() ) + member->SetGraph( aGraph ); + } }