From 11bf119232b528e4d4ef6efa754fb70706308861 Mon Sep 17 00:00:00 2001
From: David Robillard <d@drobilla.net>
Date: Sat, 30 May 2009 16:28:44 +0000
Subject: Fix crash when clearing patch that contains a patch (deactivate nodes
 on clear patch).

git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2050 a436a847-0d15-0410-975c-d299462d15a1
---
 src/engine/events/ClearPatchEvent.cpp | 18 +++++++++++++++---
 src/engine/events/ClearPatchEvent.hpp |  2 +-
 2 files changed, 16 insertions(+), 4 deletions(-)

(limited to 'src')

diff --git a/src/engine/events/ClearPatchEvent.cpp b/src/engine/events/ClearPatchEvent.cpp
index ccb84d48..3a016a66 100644
--- a/src/engine/events/ClearPatchEvent.cpp
+++ b/src/engine/events/ClearPatchEvent.cpp
@@ -74,6 +74,10 @@ ClearPatchEvent::pre_process()
 					SharedPtr<PortImpl> port = PtrCast<PortImpl>(i->second);
 					if (port)
 						++port_count;
+
+					SharedPtr<NodeImpl> node = PtrCast<NodeImpl>(i->second);
+					if (node)
+						node->deactivate();
 				}
 
 				_driver_ports = new DriverPorts(port_count, NULL);
@@ -139,9 +143,13 @@ ClearPatchEvent::post_process()
 		assert(_patch->num_ports() == 0);
 		assert(_patch->connections().size() == 0);
 
-		// Reply
-		_responder->respond_ok();
-		_engine.broadcaster()->send_clear_patch(_patch_path);
+		// Deactivate nodes
+		for (EngineStore::Objects::iterator i = _removed_table->begin();
+				i != _removed_table->end(); ++i) {
+			SharedPtr<NodeImpl> node = PtrCast<NodeImpl>(i->second);
+			if (node)
+				node->deactivate();
+		}
 
 		// Unregister and destroy driver ports
 		if (_driver_ports) {
@@ -155,6 +163,10 @@ ClearPatchEvent::post_process()
 			delete _driver_ports;
 		}
 
+		// Reply
+		_responder->respond_ok();
+		_engine.broadcaster()->send_clear_patch(_patch_path);
+
 	} else {
 		_responder->respond_error(string("Patch ") + _patch_path.str() + " not found");
 	}
diff --git a/src/engine/events/ClearPatchEvent.hpp b/src/engine/events/ClearPatchEvent.hpp
index e121c423..4dc7dddb 100644
--- a/src/engine/events/ClearPatchEvent.hpp
+++ b/src/engine/events/ClearPatchEvent.hpp
@@ -54,7 +54,7 @@ private:
 	typedef Raul::Array<Raul::List<DriverPort*>::Node*> DriverPorts;
 	DriverPorts* _driver_ports;
 
-	SharedPtr< Raul::Table<Raul::Path, SharedPtr<Shared::GraphObject> > > _removed_table;
+	SharedPtr<EngineStore::Objects> _removed_table;
 };
 
 
-- 
cgit v1.2.1