diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index f934db3cd8..40706e971a 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -1349,11 +1349,15 @@ void CONNECTION_GRAPH::generateBusAliasMembers() wxString name = conn->FullLocalName(); CONNECTION_SUBGRAPH* new_sg = new CONNECTION_SUBGRAPH( this ); + + // This connection cannot form a part of the item because the item is not, itself + // connected to this subgraph. It exists as part of a virtual item that may be connected + // to other items but is not in the schematic. SCH_CONNECTION* new_conn = new SCH_CONNECTION( item, subgraph->m_sheet ); new_conn->SetGraph( this ); - new_conn->SetName( name ); new_conn->SetType( CONNECTION_TYPE::NET ); + subgraph->StoreImplicitConnection( new_conn ); int code = assignNewNetCode( *new_conn ); wxLogTrace( ConnTrace, wxS( "SG(%ld), Adding full local name (%s) with sg (%d) on subsheet %s" ), subgraph->m_code, diff --git a/eeschema/connection_graph.h b/eeschema/connection_graph.h index dc2880df62..d5dc1b1d6e 100644 --- a/eeschema/connection_graph.h +++ b/eeschema/connection_graph.h @@ -89,7 +89,11 @@ public: m_hier_parent( nullptr ) {} - ~CONNECTION_SUBGRAPH() = default; + ~CONNECTION_SUBGRAPH() + { + for( SCH_CONNECTION* connection : m_bus_element_connections ) + delete connection; + } /** * Determines which potential driver should drive the subgraph. @@ -162,6 +166,13 @@ public: void RemoveItem( SCH_ITEM* aItem ); + // Use this to keep a connection pointer that is not owned by any item + // This will be destroyed with the subgraph + void StoreImplicitConnection( SCH_CONNECTION* aConnection ) + { + m_bus_element_connections.insert( aConnection ); + } + private: wxString driverName( SCH_ITEM* aItem ) const; @@ -251,6 +262,10 @@ public: /// A cache of escaped netnames from schematic items mutable std::unordered_map m_driver_name_cache; + /// A cache of connections that are part of this subgraph but that don't have + /// an owning element (i.e. bus members) + std::set m_bus_element_connections; + }; struct NET_NAME_CODE_CACHE_KEY