From 942eeb54c1a80b5567fd08eb9779d1dcb06835da Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Tue, 12 Mar 2024 23:30:11 +0000 Subject: [PATCH] Yet another osgpluginchecker rewrite It turns out that it's possible for OSG plugins to be spread across multiple directories, and OSG doesn't account for this in osgDB::listAllAvailablePlugins(), even though it works when actually loading the plugin. Instead, use code that's much more similar to how OSG actually loads plugin, and therefore less likely to miss anything. Incidentally make things much simpler as we don't need awkwardness from working around osgDB::listAllAvailablePlugins()'s limitations. --- components/misc/osgpluginchecker.cpp.in | 44 +++---------------------- 1 file changed, 4 insertions(+), 40 deletions(-) diff --git a/components/misc/osgpluginchecker.cpp.in b/components/misc/osgpluginchecker.cpp.in index 81ae73f9e3..8e57d9a5ce 100644 --- a/components/misc/osgpluginchecker.cpp.in +++ b/components/misc/osgpluginchecker.cpp.in @@ -35,50 +35,14 @@ namespace Misc bool checkRequiredOSGPluginsArePresent() { - // work around osgDB::listAllAvailablePlugins() not working on some platforms due to a suspected OSG bug - std::filesystem::path pluginDirectoryName = std::string("osgPlugins-") + std::string(osgGetVersion()); - osgDB::FilePathList& filepath = osgDB::getLibraryFilePathList(); - for (const auto& path : filepath) - { -#ifdef OSG_USE_UTF8_FILENAME - std::filesystem::path osgPath{ StringUtils::stringToU8String(path) }; -#else - std::filesystem::path osgPath{ path }; -#endif - if (!osgPath.has_filename()) - osgPath = osgPath.parent_path(); - - if (osgPath.filename() == pluginDirectoryName) - { - osgPath = osgPath.parent_path(); -#ifdef OSG_USE_UTF8_FILENAME - std::string extraPath = StringUtils::u8StringToString(osgPath.u8string()); -#else - std::string extraPath = osgPath.string(); -#endif - filepath.emplace_back(std::move(extraPath)); - } - } - - auto availableOSGPlugins = osgDB::listAllAvailablePlugins(); + // osgDB::listAllAvailablePlugins() lies, so don't use it bool haveAllPlugins = true; for (std::string_view plugin : USED_OSG_PLUGIN_NAMES) { - if (std::find_if(availableOSGPlugins.begin(), availableOSGPlugins.end(), - [&](std::string_view availablePlugin) { -#ifdef OSG_USE_UTF8_FILENAME - std::filesystem::path pluginPath{ StringUtils::stringToU8String(availablePlugin) }; -#else - std::filesystem::path pluginPath {availablePlugin}; -#endif - return pluginPath.filename() - == std::filesystem::path( - osgDB::Registry::instance()->createLibraryNameForExtension(std::string{ plugin })) - .filename(); - }) - == availableOSGPlugins.end()) + std::string libraryName = osgDB::Registry::instance()->createLibraryNameForExtension(std::string{ plugin }); + if (osgDB::findLibraryFile(libraryName).empty()) { - Log(Debug::Error) << "Missing OSG plugin: " << plugin; + Log(Debug::Error) << "Missing OSG plugin: " << libraryName; haveAllPlugins = false; } }