FindBlender: Fix null string SIGSEGV; search in PATH

This commit is contained in:
Luke Street 2021-10-26 11:32:37 -04:00
parent a2cc6cd204
commit 8c2caea934
1 changed files with 17 additions and 3 deletions

View File

@ -16,6 +16,20 @@ static const std::regex regBlenderVersion(R"(Blender (\d+)\.(\d+)(?:\.(\d+))?)",
static bool RegFileExists(const char* path) { static bool RegFileExists(const char* path) {
if (!path) if (!path)
return false; 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; hecl::Sstat theStat;
return !hecl::Stat(path, &theStat) && S_ISREG(theStat.st_mode); return !hecl::Stat(path, &theStat) && S_ISREG(theStat.st_mode);
} }
@ -83,17 +97,17 @@ std::optional<std::string> FindBlender(int& major, int& minor) {
#else #else
steamBlender += "/blender"; steamBlender += "/blender";
#endif #endif
blenderBin = steamBlender.c_str(); blenderBin = steamBlender;
if (!RegFileExists(blenderBin->c_str())) { if (!RegFileExists(blenderBin->c_str())) {
blenderBin = DEFAULT_BLENDER_BIN; blenderBin = DEFAULT_BLENDER_BIN;
if (!RegFileExists(blenderBin->c_str())) { if (!RegFileExists(blenderBin->c_str())) {
blenderBin = nullptr; blenderBin.reset();
} }
} }
} else { } else {
blenderBin = DEFAULT_BLENDER_BIN; blenderBin = DEFAULT_BLENDER_BIN;
if (!RegFileExists(blenderBin->c_str())) { if (!RegFileExists(blenderBin->c_str())) {
blenderBin = nullptr; blenderBin.reset();
} }
} }
} }