You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The CGLTF_ATOF function seems to only work properly on systems with . as decimal separator. On German Linux systems for example , is used as decimal separator, which breaks the conversion. My understanding is that this is a problem with the C standard being decimal separator dependent in the first place.
In our C++ code, we work around this the following way:
floatatof_locale_independent(char* str);
#defineCGLTF_ATOF(str) atof_locale_independent(str)
#defineCGLTF_IMPLEMENTATION
#include<cgltf.h>floatatof_locale_independent(char* str) {
//TODO: Once we have C++17 we can use std::from_chars
std::istringstream streamToParse(str);
streamToParse.imbue(std::locale("C"));
float value;
if (!(streamToParse >> value)) {
qDebug(modelformat) << "cgltf: Cannot parse float from string: " << str;
return0.0f;
}
return value;
}
It isn't really portable though since it requires gnuXX/gnu++XX (or the equivalent _GNU_SOURCE defined before including anything else with glibc), it is supported pretty widely but not everywhere (and Windows has _create_locale(LC_ALL,"C") instead of newlocale(LC_ALL, "C", NULL)).
The CGLTF_ATOF function seems to only work properly on systems with
.
as decimal separator. On German Linux systems for example,
is used as decimal separator, which breaks the conversion. My understanding is that this is a problem with the C standard being decimal separator dependent in the first place.In our C++ code, we work around this the following way:
Here is an example model which completely breaks on systems with
,
decimal separator: http://oaktown.pl/models/stopnie_2_1.gltf (model is CC0)The text was updated successfully, but these errors were encountered: