-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
contentScalingFactor uses locale-dependent conversion to string #136
Comments
C++17 is available so we can use Note that there're likely other parts in the code that are affected by locale issue, e.g. #101 |
Yep, I just wanted to point out this one ;) |
Note that |
Other points of the code that use locale-dependent conversions: https://github.com/search?q=org%3Aignitionrobotics+atof&type=code . |
More related issues:
Note that SDFormat sets
It looks like
Nice catch |
Just in case it helps: we went through this a couple of years ago in the urdf world. It is actually tricky to get right; what we settled on was this PR: ros/urdfdom_headers#42 . That seems to have solved the issue, at least in the places that use it, so you may want to copy that code. |
If anyone is curious, for fun I usually drop a link or a cross-link in robotology/idyntree#288 whenever I found a locale-related bug, the collection has been constantly growing over the years. |
I'm centralizing the information and issues related to locale independent conversions in gazebosim/gz-common#233. PRs are very welcome :) |
https://github.com/ignitionrobotics/ign-rendering/blob/e22fd80e25aa89454a2be1d69891c83c7900f4c0/ogre/src/OgreRenderEngine.cc#L651
https://github.com/ignitionrobotics/ign-rendering/blob/e22fd80e25aa89454a2be1d69891c83c7900f4c0/ogre2/src/Ogre2RenderEngine.cc#L715
std::to_string
respects locale, so if you run ign rendering on a system with e.g.LC_NUMERIC=cs_CZ.UTF-8
, it fails passing correct parameters to OGRE. See the decimal comma (not dot) incontentScalingFactor
:OGRE parses the value with
mContentScalingFactor = StringConverter::parseReal(opt->second);
which is
Real StringConverter::parseReal(const String& val, Real defaultValue) { StringStream str(val); if (msUseLocale) str.imbue(msLocale); Real ret = defaultValue; if( !(str >> ret) ) return defaultValue; return ret; }
The behavior of OGRE thus depends on whether
StringUtils::setUseLocale(true)
has been called or not, and I haven't found a reference to this function neither in OGRE nor in ign-rendering. Thus I assume in this use-case, OGRE parses the value in C locale.The ign-rendering code should either use https://en.cppreference.com/w/cpp/utility/to_chars (if C++17 is available), or
boost::lexical_cast
. Or set the locale before the call, but that might be unwanted in other parts...It'd be best to add a utility function for float->string and string->float conversions to ign-common/StringUtils, so that people can easily get the correct behavior...
The text was updated successfully, but these errors were encountered: