From c5218b13bac00fbd8c3ceb99b46063b98bc1fdd3 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 8 Jan 2007 02:41:36 +0000 Subject: Fix destruction of nodes with connections to parent patch ports. git-svn-id: http://svn.drobilla.net/lad/ingen@241 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/client/PatchModel.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/libs/client/PatchModel.cpp') diff --git a/src/libs/client/PatchModel.cpp b/src/libs/client/PatchModel.cpp index 22d39d42..1148ff61 100644 --- a/src/libs/client/PatchModel.cpp +++ b/src/libs/client/PatchModel.cpp @@ -124,14 +124,31 @@ PatchModel::remove_node(SharedPtr nm) NodeModelMap::iterator i = m_nodes.find(nm->path().name()); if (i != m_nodes.end()) { assert(i->second == nm); + + // Remove any connections which referred to this node, + // since they can't possibly exist anymore + for (list >::iterator i = m_connections.begin(); + i != m_connections.end() ; ) { + list >::iterator next = i; + ++next; + SharedPtr cm = (*i); + if (cm->src_port_path().parent() == nm->path() + || cm->dst_port_path().parent() == nm->path()) { + m_connections.erase(i); // cuts our reference + assert(!get_connection(cm->src_port_path(), cm->dst_port_path())); // no duplicates + removed_connection_sig.emit(cm->src_port_path(), cm->dst_port_path()); + } + i = next; + } + + // Remove the Node itself m_nodes.erase(i); removed_node_sig.emit(nm); - //i->second->parent().reset(); - return; + + } else { + cerr << "[PatchModel::remove_node] " << _path + << ": failed to find node " << nm->path().name() << endl; } - - cerr << "[PatchModel::remove_node] " << _path - << ": failed to find node " << nm->path().name() << endl; } #if 0 @@ -255,7 +272,6 @@ PatchModel::add_connection(SharedPtr cm) void PatchModel::remove_connection(const string& src_port_path, const string& dst_port_path) { - cerr << path() << " PatchModel::remove_connection: " << src_port_path << " -> " << dst_port_path << endl; for (list >::iterator i = m_connections.begin(); i != m_connections.end(); ++i) { SharedPtr cm = (*i); if (cm->src_port_path() == src_port_path && cm->dst_port_path() == dst_port_path) { -- cgit v1.2.1