diff options
author | David Robillard <d@drobilla.net> | 2011-01-06 00:29:28 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-01-06 00:29:28 +0000 |
commit | 352664583e87761925edda23f8bd9a9fe1777fe6 (patch) | |
tree | cc39d6385b9d140d00ec926294005730dffe1560 | |
parent | d1e4ea99369351b6b3a44ad0c3da2afd857db960 (diff) | |
download | patchage-352664583e87761925edda23f8bd9a9fe1777fe6.tar.gz patchage-352664583e87761925edda23f8bd9a9fe1777fe6.tar.bz2 patchage-352664583e87761925edda23f8bd9a9fe1777fe6.zip |
Clean up port cache (fix crashes and wacky behaviour caused when clients/ports are repeatedly created and destroyed).
git-svn-id: http://svn.drobilla.net/lad/trunk/patchage@2787 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | src/PatchageCanvas.cpp | 26 | ||||
-rw-r--r-- | src/PatchageCanvas.hpp | 2 | ||||
-rw-r--r-- | src/PatchageEvent.cpp | 18 |
3 files changed, 25 insertions, 21 deletions
diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp index 552f583..48ce657 100644 --- a/src/PatchageCanvas.cpp +++ b/src/PatchageCanvas.cpp @@ -67,11 +67,13 @@ PatchageCanvas::find_module(const string& name, ModuleType type) boost::shared_ptr<PatchagePort> PatchageCanvas::find_port(const PortID& id) { + boost::shared_ptr<PatchagePort> pp; + PortIndex::iterator i = _port_index.find(id); - if (i != _port_index.end()) + if (i != _port_index.end()) { + assert(i->second->module().lock()); return i->second; - - boost::shared_ptr<PatchagePort> pp; + } #ifdef USE_LIBJACK // Alsa ports are always indexed (or don't exist at all) @@ -98,6 +100,23 @@ PatchageCanvas::find_port(const PortID& id) return pp; } +boost::shared_ptr<PatchagePort> +PatchageCanvas::remove_port(const PortID& id) +{ + boost::shared_ptr<PatchagePort> port = find_port(id); + if (!port) + return port; + + _port_index.erase(id); + + SharedPtr<PatchageModule> module = PtrCast<PatchageModule>(port->module().lock()); + if (!module) + return port; + + module->remove_port(port); + _app->enqueue_resize(module); + return port; +} boost::shared_ptr<PatchagePort> PatchageCanvas::find_port_by_name(const std::string& client_name, @@ -218,7 +237,6 @@ PatchageCanvas::remove_item(boost::shared_ptr<Item> i) return ret; // Remove module from cache - boost::shared_ptr<PatchageModule> io_module; for (ModuleIndex::iterator i = _module_index.find(module->name()); i != _module_index.end() && i->first == module->name(); ++i) { if (i->second == module) { diff --git a/src/PatchageCanvas.hpp b/src/PatchageCanvas.hpp index c75af02..128f318 100644 --- a/src/PatchageCanvas.hpp +++ b/src/PatchageCanvas.hpp @@ -62,6 +62,8 @@ public: void add_module(const std::string& name, boost::shared_ptr<PatchageModule> module); bool remove_item(boost::shared_ptr<Item> i); + boost::shared_ptr<PatchagePort> remove_port(const PortID& id); + void destroy(); private: diff --git a/src/PatchageEvent.cpp b/src/PatchageEvent.cpp index 5b27726..dffbff3 100644 --- a/src/PatchageEvent.cpp +++ b/src/PatchageEvent.cpp @@ -53,8 +53,6 @@ PatchageEvent::execute(Patchage* patchage) if (module) { patchage->canvas()->remove_item(module); module.reset(); - } else { - Raul::error << "Unable to find client `" << _str << "' to remove" << endl; } free(_str); @@ -85,23 +83,9 @@ PatchageEvent::execute(Patchage* patchage) } else if (_type == PORT_DESTRUCTION) { - SharedPtr<PatchagePort> port = patchage->canvas()->find_port(_port_1); - + SharedPtr<PatchagePort> port = patchage->canvas()->remove_port(_port_1); if (port) { - SharedPtr<PatchageModule> module = PtrCast<PatchageModule>(port->module().lock()); - assert(module); - - module->remove_port(port); port.reset(); - - // No empty modules (for now) - if (module->num_ports() == 0) { - patchage->canvas()->remove_item(module); - module.reset(); - } else { - patchage->enqueue_resize(module); - } - } else { Raul::error << "Unable to find port `" << _port_1 << "' to destroy" << endl; } |