4242#include < boost/program_options.hpp>
4343#include < boost/filesystem.hpp>
4444#include < boost/optional.hpp>
45+ #include < boost/dll.hpp>
4546
4647#ifdef ENABLE_CGAL
4748#include < CGAL/assertions.h>
6667#include " platform/PlatformUtils.h"
6768#include " RenderStatistic.h"
6869#include " utils/StackCheck.h"
70+ #include " printutils.h"
6971
7072
7173#ifdef ENABLE_PYTHON
@@ -226,15 +228,15 @@ void set_render_color_scheme(const std::string& color_scheme, const bool exit_if
226228 */
227229void localization_init () {
228230 fs::path po_dir (PlatformUtils::resourcePath (" locale" ));
229- std::string locale_path (po_dir.string ());
231+ const std::string& locale_path (po_dir.string ());
230232
231233 if (fs::is_directory (locale_path)) {
232234 setlocale (LC_ALL, " " );
233235 bindtextdomain (" openscad" , locale_path.c_str ());
234236 bind_textdomain_codeset (" openscad" , " UTF-8" );
235237 textdomain (" openscad" );
236238 } else {
237- LOG (" Could not initialize localization. " );
239+ LOG (" Could not initialize localization (application path is '%1$s'). " , PlatformUtils::applicationPath () );
238240 }
239241}
240242
@@ -656,15 +658,6 @@ int main(int argc, char **argv)
656658 int rc = 0 ;
657659 StackCheck::inst ();
658660
659- #ifdef OPENSCAD_QTGUI
660- { // Need a dummy app instance to get the application path but it needs to be destroyed before the GUI is launched.
661- QCoreApplication app (argc, argv);
662- PlatformUtils::registerApplicationPath (app.applicationDirPath ().toLocal8Bit ().constData ());
663- }
664- #else
665- PlatformUtils::registerApplicationPath (fs::absolute (boost::filesystem::path (argv[0 ]).parent_path ()).generic_string ());
666- #endif
667-
668661#ifdef Q_OS_MACOS
669662 bool isGuiLaunched = getenv (" GUI_LAUNCHED" ) != nullptr ;
670663 auto nslog = [](const Message& msg, void *userdata) {
@@ -675,6 +668,9 @@ int main(int argc, char **argv)
675668 PlatformUtils::ensureStdIO ();
676669#endif
677670
671+ const auto applicationPath = weakly_canonical (boost::dll::program_location ().parent_path ()).generic_string ();
672+ PlatformUtils::registerApplicationPath (applicationPath);
673+
678674#ifdef ENABLE_CGAL
679675 // Always throw exceptions from CGAL, so we can catch instead of crashing on bad geometry.
680676 CGAL::set_error_behaviour (CGAL::THROW_EXCEPTION);
@@ -929,6 +925,8 @@ int main(int argc, char **argv)
929925 }
930926 }
931927
928+ PRINTDB (" Application location detected as %s" , applicationPath);
929+
932930 auto cmdlinemode = false ;
933931 if (!output_files.empty ()) { // cmd-line mode
934932 cmdlinemode = true ;
0 commit comments