From 20714a82da8b6c808be5f17d7add9e164ab154e3 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 21 Oct 2009 02:10:24 +0000 Subject: Fix crash when plugins fail to instantiate. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2199 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/LV2Node.cpp | 5 +++-- src/engine/events/CreateNode.cpp | 14 +++++++++----- src/engine/events/CreateNode.hpp | 2 ++ 3 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src/engine') diff --git a/src/engine/LV2Node.cpp b/src/engine/LV2Node.cpp index 92f32b3c..df2ccbb2 100644 --- a/src/engine/LV2Node.cpp +++ b/src/engine/LV2Node.cpp @@ -60,8 +60,9 @@ LV2Node::LV2Node(LV2Plugin* plugin, LV2Node::~LV2Node() { - for (uint32_t i=0; i < _polyphony; ++i) - slv2_instance_free((*_instances)[i]); + if (_instances) + for (uint32_t i=0; i < _polyphony; ++i) + slv2_instance_free((*_instances)[i]); delete _instances; } diff --git a/src/engine/events/CreateNode.cpp b/src/engine/events/CreateNode.cpp index 48d25348..966f96c1 100644 --- a/src/engine/events/CreateNode.cpp +++ b/src/engine/events/CreateNode.cpp @@ -54,6 +54,7 @@ CreateNode::CreateNode( , _plugin_uri(plugin_uri) , _polyphonic(polyphonic) , _patch(NULL) + , _plugin(NULL) , _node(NULL) , _compiled_patch(NULL) , _node_already_exists(false) @@ -83,16 +84,16 @@ CreateNode::pre_process() _patch = _engine.engine_store()->find_patch(_path.parent()); - PluginImpl* const plugin = (_plugin_label == "") + _plugin = (_plugin_label == "") ? _engine.node_factory()->plugin(_plugin_uri.str()) : _engine.node_factory()->plugin(_plugin_type, _plugin_lib, _plugin_label); - if (_patch && plugin) { + if (_patch && _plugin) { - _node = plugin->instantiate(_path.name(), _polyphonic, _patch, _engine); - _node->properties().insert(_properties.begin(), _properties.end()); + _node = _plugin->instantiate(_path.name(), _polyphonic, _patch, _engine); if (_node != NULL) { + _node->properties().insert(_properties.begin(), _properties.end()); _node->activate(); // This can be done here because the audio thread doesn't touch the @@ -134,10 +135,13 @@ CreateNode::post_process() } else if (_patch == NULL) { msg = "Could not find patch '" + _path.parent().str() +"' to add node."; _responder->respond_error(msg); - } else if (_node == NULL) { + } else if (_plugin == NULL) { msg = "Unable to load node "; msg += _path.str() + " (you're missing the plugin " + _plugin_uri.str() + ")"; _responder->respond_error(msg); + } else if (_node == NULL) { + msg = "Failed to instantiate plugin " + _plugin_uri.str(); + _responder->respond_error(msg); } else { _responder->respond_ok(); _engine.broadcaster()->send_object(_node, true); // yes, send ports diff --git a/src/engine/events/CreateNode.hpp b/src/engine/events/CreateNode.hpp index e44008e4..8f2379b0 100644 --- a/src/engine/events/CreateNode.hpp +++ b/src/engine/events/CreateNode.hpp @@ -25,6 +25,7 @@ namespace Ingen { class PatchImpl; +class PluginImpl; class NodeImpl; class CompiledPatch; @@ -59,6 +60,7 @@ private: std::string _plugin_label; bool _polyphonic; PatchImpl* _patch; + PluginImpl* _plugin; NodeImpl* _node; CompiledPatch* _compiled_patch; ///< Patch's new process order bool _node_already_exists; -- cgit v1.2.1