diff plugin/FeatureExtractionPluginFactory.cpp @ 251:db0dd744fa8d

* Fix hang and memory leak on startup when encountering a pre-Vamp-1.0 plugin
author Chris Cannam
date Tue, 20 Mar 2007 11:49:11 +0000
parents d3ac9f953ebf
children dc46851837d6
line wrap: on
line diff
--- a/plugin/FeatureExtractionPluginFactory.cpp	Mon Mar 12 15:36:31 2007 +0000
+++ b/plugin/FeatureExtractionPluginFactory.cpp	Tue Mar 20 11:49:11 2007 +0000
@@ -137,14 +137,42 @@
             const VampPluginDescriptor *descriptor = 0;
             int index = 0;
 
+            std::map<std::string, int> known;
+            bool ok = true;
+
             while ((descriptor = fn(VAMP_API_VERSION, index))) {
-                QString id = PluginIdentifier::createIdentifier
-                    ("vamp", soname, descriptor->identifier);
-                rv.push_back(id);
+
+                if (known.find(descriptor->identifier) != known.end()) {
+                    std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Plugin library "
+                              << soname.toStdString()
+                              << " returns the same plugin identifier \""
+                              << descriptor->identifier << "\" at indices "
+                              << known[descriptor->identifier] << " and "
+                              << index << std::endl;
+                    std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: Avoiding this library (obsolete API?)" << std::endl;
+                    ok = false;
+                    break;
+                } else {
+                    known[descriptor->identifier] = index;
+                }
+
+                ++index;
+            }
+
+            if (ok) {
+
+                index = 0;
+
+                while ((descriptor = fn(VAMP_API_VERSION, index))) {
+
+                    QString id = PluginIdentifier::createIdentifier
+                        ("vamp", soname, descriptor->identifier);
+                    rv.push_back(id);
 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
-                std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: Found plugin id " << id.toStdString() << std::endl;
+                    std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: Found plugin id " << id.toStdString() << " at index " << index << std::endl;
 #endif
-                ++index;
+                    ++index;
+                }
             }
             
             if (DLCLOSE(libraryHandle) != 0) {