Open erslavin opened 1 month ago
Filed as internal issue #USD-9954
From a discussion, a plausible solution is to specialize using std::to_chars
since it is optimized for performance, and does not use locale.
eg
std::string result(32, '\0'); // big enough
auto [ptr, ec] = std::to_chars(&result[0], &result[0] + result.size(), value);
Description of Issue
The USDA writer appears to be sensitive to the current locale setting when writing integer content. Indeed digging down it looks to be using
TfStringify
, with no specialization for integers, which results in the underlyingostream
being initialized with whatever the current global locale is set to. I isolated this by adding the following sequence into the test forTfStringUtils
:Indeed, this fails on the line you would expect:
`TF_AXIOM(TfStringify(1000) == "1000");
Either this behavior should be guarded against in
TfStringify
by potentially specializing for integer values, or if not globally desirable forTfStringify
the USDA writer needs to be aware that this is a possibility and initialize the writes with the standard C++ locale prior to using the streams (and restore it after write is complete).Steps to Reproduce
TfStringUtils
testsTfStringUtils
test to note the failureA similar issue was noted here (likely with the same underlying cause), but closed: https://github.com/PixarAnimationStudios/OpenUSD/issues/1350
System Information (OS, Hardware)
Windows
Package Versions
Current
dev
branchBuild Flags