diff --git a/src/FontCache.cc b/src/FontCache.cc index 7153449ab3..e5d11629e4 100644 --- a/src/FontCache.cc +++ b/src/FontCache.cc @@ -130,7 +130,8 @@ FontCache::FontCache() // For system installs and dev environments, we leave this alone fs::path fontdir(PlatformUtils::resourcePath("fonts")); if (fs::is_regular_file(fontdir / "fonts.conf")) { - PlatformUtils::setenv("FONTCONFIG_PATH", (fs::absolute(fontdir).generic_string()).c_str(), 0); + auto abspath = fontdir.empty() ? fs::current_path() : fs::absolute(fontdir); + PlatformUtils::setenv("FONTCONFIG_PATH", (abspath.generic_string()).c_str(), 0); } // Just load the configs. We'll build the fonts once all configs are loaded diff --git a/src/core/parsersettings.cc b/src/core/parsersettings.cc index 4a242c4c78..d715f4fb8c 100644 --- a/src/core/parsersettings.cc +++ b/src/core/parsersettings.cc @@ -148,11 +148,18 @@ void parser_init() std::string sep = PlatformUtils::pathSeparatorChar(); using string_split_iterator = boost::split_iterator; for (string_split_iterator it = boost::make_split_iterator(paths, boost::first_finder(sep, boost::is_iequal())); it != string_split_iterator(); ++it) { - add_librarydir(fs::absolute(fs::path(boost::copy_range(*it))).generic_string()); + auto str{boost::copy_range(*it)}; + fs::path abspath = str.empty() ? fs::current_path() : fs::absolute(fs::path(str)); + add_librarydir(abspath.generic_string()); } } add_librarydir(PlatformUtils::userLibraryPath()); - add_librarydir(fs::absolute(PlatformUtils::resourcePath("libraries")).string()); + fs::path libpath = PlatformUtils::resourcePath("libraries"); + // std::filesystem::absolute() will throw if passed empty path + if (libpath.empty()) { + libpath = fs::current_path(); + } + add_librarydir(fs::absolute(libpath).string()); } diff --git a/src/openscad.cc b/src/openscad.cc index 52470fb284..70901c4e5a 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -329,7 +329,8 @@ struct CommandLine int do_export(const CommandLine& cmd, const RenderVariables& render_variables, FileFormat export_format, SourceFile *root_file) { auto filename_str = fs::path(cmd.output_file).generic_string(); - auto fpath = fs::absolute(fs::path(cmd.filename)); + // Avoid possibility of fs::absolute throwing when passed an empty path + auto fpath = cmd.filename.empty() ? fs::current_path() : fs::absolute(fs::path(cmd.filename)); auto fparent = fpath.parent_path(); // set CWD relative to source file