From 8c2caea9340833f090412477afd6ffb033549052 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Tue, 26 Oct 2021 11:32:37 -0400 Subject: [PATCH] FindBlender: Fix null string SIGSEGV; search in PATH --- hecl/lib/Blender/FindBlender.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/hecl/lib/Blender/FindBlender.cpp b/hecl/lib/Blender/FindBlender.cpp index 08bdc8a32..3c2de3717 100644 --- a/hecl/lib/Blender/FindBlender.cpp +++ b/hecl/lib/Blender/FindBlender.cpp @@ -16,6 +16,20 @@ static const std::regex regBlenderVersion(R"(Blender (\d+)\.(\d+)(?:\.(\d+))?)", static bool RegFileExists(const char* path) { if (!path) return false; +#if !defined(WIN32) + if (path[0] != '/') { + auto envPath = hecl::GetEnv("PATH"); + if (envPath) { + std::istringstream iss(*envPath); + std::string item; + while (std::getline(iss, item, ':')) { + if (RegFileExists((item + "/" + path).c_str())) { + return true; + } + } + } + } +#endif hecl::Sstat theStat; return !hecl::Stat(path, &theStat) && S_ISREG(theStat.st_mode); } @@ -83,17 +97,17 @@ std::optional FindBlender(int& major, int& minor) { #else steamBlender += "/blender"; #endif - blenderBin = steamBlender.c_str(); + blenderBin = steamBlender; if (!RegFileExists(blenderBin->c_str())) { blenderBin = DEFAULT_BLENDER_BIN; if (!RegFileExists(blenderBin->c_str())) { - blenderBin = nullptr; + blenderBin.reset(); } } } else { blenderBin = DEFAULT_BLENDER_BIN; if (!RegFileExists(blenderBin->c_str())) { - blenderBin = nullptr; + blenderBin.reset(); } } }