Skip to content

Commit

Permalink
Use boost::dll::program_location() for detecting the resource location.
Browse files Browse the repository at this point in the history
  • Loading branch information
t-paul committed Oct 27, 2024
1 parent 0ab2ba2 commit 55cc6cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
18 changes: 8 additions & 10 deletions src/openscad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <boost/program_options.hpp>
#include <boost/filesystem.hpp>
#include <boost/optional.hpp>
#include <boost/dll.hpp>

#ifdef ENABLE_CGAL
#include <CGAL/assertions.h>
Expand All @@ -66,6 +67,7 @@
#include "platform/PlatformUtils.h"
#include "RenderStatistic.h"
#include "utils/StackCheck.h"
#include "printutils.h"


#ifdef ENABLE_PYTHON
Expand Down Expand Up @@ -234,7 +236,7 @@ void localization_init() {
bind_textdomain_codeset("openscad", "UTF-8");
textdomain("openscad");
} else {
LOG("Could not initialize localization.");
LOG("Could not initialize localization (application path is '%1$s').", PlatformUtils::applicationPath());
}
}

Expand Down Expand Up @@ -656,15 +658,6 @@ int main(int argc, char **argv)
int rc = 0;
StackCheck::inst();

#ifdef OPENSCAD_QTGUI
{ // Need a dummy app instance to get the application path but it needs to be destroyed before the GUI is launched.
QCoreApplication app(argc, argv);
PlatformUtils::registerApplicationPath(app.applicationDirPath().toLocal8Bit().constData());
}
#else
PlatformUtils::registerApplicationPath(fs::absolute(boost::filesystem::path(argv[0]).parent_path()).generic_string());
#endif

#ifdef Q_OS_MACOS
bool isGuiLaunched = getenv("GUI_LAUNCHED") != nullptr;
auto nslog = [](const Message& msg, void *userdata) {
Expand All @@ -675,6 +668,9 @@ int main(int argc, char **argv)
PlatformUtils::ensureStdIO();
#endif

const auto applicationPath = weakly_canonical(boost::dll::program_location().parent_path()).generic_string();
PlatformUtils::registerApplicationPath(applicationPath);

#ifdef ENABLE_CGAL
// Always throw exceptions from CGAL, so we can catch instead of crashing on bad geometry.
CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION);
Expand Down Expand Up @@ -929,6 +925,8 @@ int main(int argc, char **argv)
}
}

PRINTDB("Application location detected as %s", applicationPath);

auto cmdlinemode = false;
if (!output_files.empty()) { // cmd-line mode
cmdlinemode = true;
Expand Down
1 change: 0 additions & 1 deletion src/platform/PlatformUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ static std::string lookupResourcesPath()
const char *searchpath[] = {
RESOURCE_FOLDER("../share/openscad"),
RESOURCE_FOLDER("../../share/openscad"),
"usr/share/openscad", // AppImage, no build suffix
".",
"..",
"../..",
Expand Down

0 comments on commit 55cc6cb

Please sign in to comment.