nxdk
nxdk copied to clipboard
Crash when declaring std::locale
This line makes the program crash at the beginning, without running a single line. It doesn't matter if the declaration is done as a local variable or as a global one (it fails on both ways):
std::locale const f_portable_locale("C");
The following gist has a minimal program to reproduce this issue:
https://gist.github.com/hcfcoder/326b826dbd13e64f19110bd9905dfaae
I have updated the program, removing the SDL functions and library, to make it even more minimal.
It appears that the program doesn't actually crash, it exits because it's unable to recover from an error.
We don't really support locales yet, so we're using the stubs included in libc++. Apparently this is not enough to allow constructing a std::locale
object though: The constructor contains the line install(new collate_byname<char>(name_))
, which calls into https://github.com/XboxDev/nxdk-libcxx/blob/c594e975f383418d98dbdf35a8f2fff4699a62fb/src/locale.cpp#L674
The stubbed newlocale
function returns NULL
, causing this function to try to throw an exception via __throw_runtime_error
, but because C++ exceptions are disabled, that function makes the program quit instead.
I'm not sure why libc++ does it this way, but until we have better locale support, it's probably best to avoid using std::locale
at all.
Thank you very much, everything is clear!
As these errors can be hard to debug, would it be worth to put a warning message in the "locale" constructor, so that when someone compiles a program and "locale" is used, a warning message is triggered? I know that it is a bad solution, but leaving as it is can make someone waste a lot of time trying to figure out where is his error...