diff --git a/src/supertux/error_handler.cpp b/src/supertux/error_handler.cpp index a06dff1f1c9..b07e5517b08 100644 --- a/src/supertux/error_handler.cpp +++ b/src/supertux/error_handler.cpp @@ -16,9 +16,12 @@ #include "supertux/error_handler.hpp" -// apparently this is exclusive to glibc as of 2020, keep checking for -// llvm/msvc equivalent from time to time ~ Semphris -#ifdef __GLIBCXX__ +// execinfo.h as a built-in libc feature is exclusive to glibc as of 2020. +// On FreeBSD and musl systems, an external libexecinfo is available, but +// it has to be explicitly linked into the final executable. +// This is a *libc* feature, not a compiler one; furthermore, it's possible +// to verify its availability in CMakeLists.txt, if one is so inclined. +#ifdef __GLIBC__ #include #include #include @@ -29,7 +32,7 @@ bool ErrorHandler::m_handing_error = false; void ErrorHandler::set_handlers() { -#ifdef __GLIBCXX__ +#ifdef __GLIBC__ signal(SIGSEGV, handle_error); #endif } @@ -56,7 +59,7 @@ ErrorHandler::handle_error(int sig) void ErrorHandler::print_stack_trace() { -#ifdef __GLIBCXX__ +#ifdef __GLIBC__ void *array[10]; size_t size; diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index ad5e3fde69b..efd655855b0 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -563,10 +563,20 @@ Main::run(int argc, char** argv) _wfreopen(w_errpath.c_str(), L"a", stderr); #endif - // Create and install global locale - std::locale::global(boost::locale::generator().generate("")); - // Make boost.filesystem use it - boost::filesystem::path::imbue(std::locale()); + // Create and install global locale - this can fail on some situations: + // - with bad values for env vars (LANG, LC_ALL, ...) + // - targets where libstdc++ uses its generic locales code (https://gcc.gnu.org/legacy-ml/libstdc++/2003-02/msg00345.html) + // NOTE: when moving to C++ >= 17, keep the try-catch block, but use std::locale:global(std::locale("")); + try + { + std::locale::global(boost::locale::generator().generate("")); + // Make boost.filesystem use it + boost::filesystem::path::imbue(std::locale()); + } + catch(const std::runtime_error& err) + { + std::cout << "Warning: " << err.what() << std::endl; + } int result = 0;