diff --git a/src/core/vscore.cpp b/src/core/vscore.cpp index 8fac88c8..f5a8ce75 100644 --- a/src/core/vscore.cpp +++ b/src/core/vscore.cpp @@ -2502,7 +2502,7 @@ void VSPlugin::load(const std::string &relFilename, bool lazy) { throw VSException("Core only supports API R" + std::to_string(VAPOURSYNTH_API_MAJOR) + "." + std::to_string(VAPOURSYNTH_API_MINOR) + " but the loaded plugin requires API R" + std::to_string(apiMajor) + "." + std::to_string(apiMinor) + "; Filename: " + relFilename + "; Name: " + fullname); } - if (lazy) { + if (lazy && getenv("VSC_DISABLE_LAZY_PLUGIN") == nullptr) { unload(true); hasConfig = false; readOnly = false; @@ -2600,8 +2600,11 @@ bool VSPlugin::registerFunction(const std::string &name, const std::string &args VSMap *VSPlugin::invoke(const std::string &funcName, const VSMap &args) { auto it = funcs.find(funcName); if (it != funcs.end()) { - if (it->second.isLazy()) - load(filename, false); + std::call_once(lazyOnce, [&it, this]() { + if (it->second.isLazy()) { + load(filename, false); + } + }); return it->second.invoke(args); } else { VSMap *v = new VSMap(); diff --git a/src/core/vscore.h b/src/core/vscore.h index 4ffe4f45..7de31f4b 100644 --- a/src/core/vscore.h +++ b/src/core/vscore.h @@ -1008,6 +1008,7 @@ struct VSPluginFunction { std::string getV3ArgString() const; bool rename(const std::string &newname); // 'vs-c' + // 'vs-c' lazy plugin support void setLazy() { func = nullptr; functionData = nullptr; } bool isLazy() const { return func == nullptr; } void setFunc(VSPublicFunction f, void *d) { func = f; functionData = d; } @@ -1036,11 +1037,12 @@ struct VSPlugin { std::map funcs; std::mutex functionLock; VSCore *core; + std::once_flag lazyOnce; public: explicit VSPlugin(VSCore *core); VSPlugin(const std::string &relFilename, const std::string &forcedNamespace, const std::string &forcedId, bool altSearchPath, VSCore *core, bool lazy = false); - void load(const std::string &relFilename, bool lazy = false); - void unload(bool lazy = false); + void load(const std::string &relFilename, bool lazy = false); // 'vs-c' + void unload(bool lazy = false); // 'vs-c' ~VSPlugin(); void lock() { readOnly = true; } void unlock() { readOnly = false; } // 'vs-c'