From aad099559645a96cdc553363f913c6a5c4e964f1 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 12 Feb 2025 16:52:55 +0100 Subject: [PATCH] Handle multiple paths in RGL_PATTERNS_DIR correctly --- RGLServerPlugin/src/LidarPatternLoader.cc | 24 +++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/RGLServerPlugin/src/LidarPatternLoader.cc b/RGLServerPlugin/src/LidarPatternLoader.cc index 73adfc8..bdc39eb 100644 --- a/RGLServerPlugin/src/LidarPatternLoader.cc +++ b/RGLServerPlugin/src/LidarPatternLoader.cc @@ -207,8 +207,28 @@ bool LidarPatternLoader::LoadPatternFromPreset(const sdf::ElementConstPtr& sdf, } auto [presetPath, presetPatternCount] = presetNameToLoadInfo[presetName]; - if (const char* presetDir = std::getenv(PATTERNS_DIR_ENV)) { - presetPath = fs::path(presetDir) / presetPath; + if (const char* presetDirs = std::getenv(PATTERNS_DIR_ENV)) { + + std::stringstream ss(presetDirs); + std::string dir; + bool found = false; + + while (std::getline(ss, dir, ':')) { + fs::path potentialPath = fs::path(dir) / presetPath; + + if (fs::exists(potentialPath)) { + presetPath = potentialPath; + found = true; + break; + } + } + + if (!found) { + gzerr << "Failed to find preset '" << presetName << "' in any of the directories in '" << PATTERNS_DIR_ENV << "'\n"; + return false; + } + + presetPath = fs::path(presetDirs) / presetPath; } gzmsg << "Loading pattern_preset '" << presetName << "'...\n";