From 59a2893b937f58d5348c89a94293c4994158f2a2 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Tue, 21 Sep 2021 17:07:51 +0200 Subject: [PATCH 1/3] add a check if plugin has already been loaded with a different path --- .../src/sofa/helper/system/PluginManager.cpp | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/system/PluginManager.cpp b/SofaKernel/modules/SofaHelper/src/sofa/helper/system/PluginManager.cpp index 7bdd294a8d9..98c1a66b673 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/system/PluginManager.cpp +++ b/SofaKernel/modules/SofaHelper/src/sofa/helper/system/PluginManager.cpp @@ -273,6 +273,18 @@ Plugin* PluginManager::getPlugin(const std::string& plugin, const std::string& / } else { + // check if a plugin with a same name but a different path is loaded + // problematic case per se but at least we can warn the user + const auto& pluginName = sofa::helper::system::SetDirectory::GetFileNameWithoutExtension(pluginPath.c_str()); + for (auto& k : m_pluginMap) + { + if (pluginName == k.second.getModuleName()) + { + msg_warning("PluginManager") << "Plugin " << pluginName << " is already loaded from a different path, check you configuration."; + return &k.second; + } + } + msg_info("PluginManager") << "Plugin not found in loaded plugins: " << plugin; return nullptr; } @@ -417,11 +429,26 @@ bool PluginManager::pluginIsLoaded(const std::string& plugin) if (!FileSystem::isFile(plugin)) { // path is invalid - msg_error("PluginManager") << "File not found: " << plugin; + msg_error("PluginManager") << "Could not check if the plugin is loaded as the path is invalid: " << plugin; return false; } pluginPath = plugin; + + // argument is a path but we need to check if it was not already loaded with a different path + const auto& pluginName = sofa::helper::system::SetDirectory::GetFileNameWithoutExtension(pluginPath.c_str()); + for (const auto& k : m_pluginMap) + { + if (pluginName == k.second.getModuleName() && pluginPath != k.first) + { + // we did find a plugin with the same, but it does not have the same path... + msg_warning("PluginManager") << "This plugin " << pluginName << " has been loaded from a different path, it will certainly lead to bugs or crashes... " << msgendl + << "You tried to load: " << pluginPath << msgendl + << "Already loaded: " << k.first; + return true; + } + } + } else { From 4211ad041c667600204189e5029b18abf77b8e43 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Thu, 23 Sep 2021 11:25:41 +0200 Subject: [PATCH 2/3] Update SofaKernel/modules/SofaHelper/src/sofa/helper/system/PluginManager.cpp Co-authored-by: Alex Bilger --- .../SofaHelper/src/sofa/helper/system/PluginManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/system/PluginManager.cpp b/SofaKernel/modules/SofaHelper/src/sofa/helper/system/PluginManager.cpp index 98c1a66b673..2e4155d7592 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/system/PluginManager.cpp +++ b/SofaKernel/modules/SofaHelper/src/sofa/helper/system/PluginManager.cpp @@ -437,9 +437,9 @@ bool PluginManager::pluginIsLoaded(const std::string& plugin) // argument is a path but we need to check if it was not already loaded with a different path const auto& pluginName = sofa::helper::system::SetDirectory::GetFileNameWithoutExtension(pluginPath.c_str()); - for (const auto& k : m_pluginMap) + for (const auto& [loadedPath, loadedPlugin] : m_pluginMap) { - if (pluginName == k.second.getModuleName() && pluginPath != k.first) + if (pluginName == loadedPlugin.getModuleName() && pluginPath != loadedPath) { // we did find a plugin with the same, but it does not have the same path... msg_warning("PluginManager") << "This plugin " << pluginName << " has been loaded from a different path, it will certainly lead to bugs or crashes... " << msgendl From bc19fe6a37ef7c40b51c4f1e2d79f6d57d68e1c1 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Thu, 23 Sep 2021 12:52:14 +0200 Subject: [PATCH 3/3] fix compil --- .../modules/SofaHelper/src/sofa/helper/system/PluginManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SofaKernel/modules/SofaHelper/src/sofa/helper/system/PluginManager.cpp b/SofaKernel/modules/SofaHelper/src/sofa/helper/system/PluginManager.cpp index 2e4155d7592..112a5573684 100644 --- a/SofaKernel/modules/SofaHelper/src/sofa/helper/system/PluginManager.cpp +++ b/SofaKernel/modules/SofaHelper/src/sofa/helper/system/PluginManager.cpp @@ -444,7 +444,7 @@ bool PluginManager::pluginIsLoaded(const std::string& plugin) // we did find a plugin with the same, but it does not have the same path... msg_warning("PluginManager") << "This plugin " << pluginName << " has been loaded from a different path, it will certainly lead to bugs or crashes... " << msgendl << "You tried to load: " << pluginPath << msgendl - << "Already loaded: " << k.first; + << "Already loaded: " << loadedPath; return true; } }