diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index 38b296f569..f71ab4c6b8 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -1367,11 +1367,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) " diff --git a/eeschema/connection_graph.h b/eeschema/connection_graph.h index 35e392543a..cbf0bd64c8 100644 --- a/eeschema/connection_graph.h +++ b/eeschema/connection_graph.h @@ -89,7 +89,11 @@ public: m_driver_connection( nullptr ) {} - ~CONNECTION_SUBGRAPH() = default; + ~CONNECTION_SUBGRAPH() + { + for( SCH_CONNECTION* connection : m_bus_element_connections ) + delete connection; + } friend class CONNECTION_GRAPH; @@ -195,6 +199,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; @@ -286,6 +297,10 @@ private: /// Cache for driver connection. SCH_CONNECTION* m_driver_connection; + + /// 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