From 352664583e87761925edda23f8bd9a9fe1777fe6 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 6 Jan 2011 00:29:28 +0000 Subject: 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 --- src/PatchageCanvas.cpp | 26 ++++++++++++++++++++++---- src/PatchageCanvas.hpp | 2 ++ 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 PatchageCanvas::find_port(const PortID& id) { + boost::shared_ptr 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 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 +PatchageCanvas::remove_port(const PortID& id) +{ + boost::shared_ptr port = find_port(id); + if (!port) + return port; + + _port_index.erase(id); + + SharedPtr module = PtrCast(port->module().lock()); + if (!module) + return port; + + module->remove_port(port); + _app->enqueue_resize(module); + return port; +} boost::shared_ptr PatchageCanvas::find_port_by_name(const std::string& client_name, @@ -218,7 +237,6 @@ PatchageCanvas::remove_item(boost::shared_ptr i) return ret; // Remove module from cache - boost::shared_ptr 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 module); bool remove_item(boost::shared_ptr i); + boost::shared_ptr 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 port = patchage->canvas()->find_port(_port_1); - + SharedPtr port = patchage->canvas()->remove_port(_port_1); if (port) { - SharedPtr module = PtrCast(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; } -- cgit v1.2.1