summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-07-03 04:38:56 +0000
committerDavid Robillard <d@drobilla.net>2007-07-03 04:38:56 +0000
commitfd072bfb096e6efd88de1e058a355128b312d6d8 (patch)
treeb85bfa66762f1f5e3332b050423d6cfc3a91a6ca
parentc1554628bed17ca47c8b81537bae158feae56ee9 (diff)
downloadlilv-fd072bfb096e6efd88de1e058a355128b312d6d8.tar.gz
lilv-fd072bfb096e6efd88de1e058a355128b312d6d8.tar.bz2
lilv-fd072bfb096e6efd88de1e058a355128b312d6d8.zip
Fail gracefully when a plugin can't be instantiated (instead of crashing on assert failure).
git-svn-id: http://svn.drobilla.net/lad/slv2@559 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/plugininstance.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/plugininstance.c b/src/plugininstance.c
index be2252c..62b4c7d 100644
--- a/src/plugininstance.c
+++ b/src/plugininstance.c
@@ -99,20 +99,21 @@ slv2_plugin_instantiate(SLV2Plugin plugin,
}
}
- assert(result);
- assert(slv2_plugin_get_num_ports(plugin) > 0);
+ if (result) {
+ assert(slv2_plugin_get_num_ports(plugin) > 0);
+
+ // Failed to instantiate
+ if (result->lv2_handle == NULL) {
+ //printf("Failed to instantiate %s\n", plugin->plugin_uri);
+ free(result);
+ return NULL;
+ }
- // Failed to instantiate
- if (result->lv2_handle == NULL) {
- //printf("Failed to instantiate %s\n", plugin->plugin_uri);
- free(result);
- return NULL;
+ // "Connect" all ports to NULL (catches bugs)
+ for (uint32_t i=0; i < slv2_plugin_get_num_ports(plugin); ++i)
+ result->lv2_descriptor->connect_port(result->lv2_handle, i, NULL);
}
- // "Connect" all ports to NULL (catches bugs)
- for (uint32_t i=0; i < slv2_plugin_get_num_ports(plugin); ++i)
- result->lv2_descriptor->connect_port(result->lv2_handle, i, NULL);
-
if (local_host_features)
free(host_features);
@@ -123,6 +124,9 @@ slv2_plugin_instantiate(SLV2Plugin plugin,
void
slv2_instance_free(SLV2Instance instance)
{
+ if (!instance)
+ return;
+
struct _Instance* i = (struct _Instance*)instance;
i->lv2_descriptor->cleanup(i->lv2_handle);
i->lv2_descriptor = NULL;