Skip to content
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

obj_encoder functions produce invalid OBJ files when using a non-english numeric locale #1035

Closed
tim-depthkit opened this issue Dec 22, 2023 · 2 comments
Assignees

Comments

@tim-depthkit
Copy link

I am using draco within my project as a library to enable exporting meshes directly to DRC, OBJ, PLY, etc.

If I set the program locale to the system default as follows:

setlocale(LC_ALL, ".UTF8");

and then I use the obj_encoder functions to save a mesh to an OBJ file, the result is unusable, as OBJ requires a . decimal separator, and the system default is set to a locale which uses ,.

I can get around this by adding another line to override the numeric locale:

setlocale(LC_NUMERIC, "en_US.UTF8");

However, I should not be required to do so, as this affects all floating point string conversions application wide.

@ondys ondys self-assigned this Jan 9, 2024
@ondys
Copy link
Collaborator

ondys commented Jan 18, 2024

I believe this should be fixed in the latest release, please give it a try.

@ondys ondys closed this as completed Jan 18, 2024
@tim-depthkit
Copy link
Author

This is still an issue in the latest release (1.5.7). I must still use the work around outlined above to ensure I get period decimal separators when my system is set to a region that uses a comma decimal separator.

Looking at the OBJ encoder code, I see the following in obj_encoder.cc

void ObjEncoder::EncodeFloat(float val) {
  // Use %F instead of %f to make the floating point non-locale aware.
  snprintf(num_buffer_, sizeof(num_buffer_), "%F", val);
  buffer()->Encode(num_buffer_, strlen(num_buffer_));
}

Both of these sources do not mention anything about the uppercase F vs lowercase f having anything to do with locale, but rather whether or not to print things like infinity or NAN in upper or lower case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants