The dot that put me in a comma

This is an update on Nathan’s previous post about a pretty nasty Heisenbug. The symptoms were that the static voxelizing function was not working in specific conditions. More specifically, it would work when used in the main function but would not work when used in a Qt Widget function. However, that was on my own computer and when not using a debugging tool. When using Qt Creator’s debugging interface (based on gdb), the program would run just fine. It would also run as expected on Nathan’s computer.

Nathan worked yesterday on making the program run independently from the Linux distribution used as there was an issue with Opencv versions and packages contents between Ubuntu (that Salomé and I use) and Archlinux that Nathan uses.

String Theory

We tried inspecting the values of the voxelizing variables and narrowed it down to the input of the algorithm. We use a homemade method to read from an obj file and extract the faces to a vector that will be used for computation. The faces had coordinates that were all 0 but had a correct sign. Since the strings parsed from the file were correct but not the numbers extraced, this was a clear string to double conversion issue.

*stod wants to know your location*

We looked at the documentations for the stod function that converts a string to a double looking for an issue with the input. We also tried using lower level functions like strtod that unlike stod uses C strings. After much thinking, we noticed that the displayed number after conversion were displayed with a comma and not a dot. That is when we found that stod is locale dependent and the locale in the Qt Widget made it so floating point and double precision numbers used commas instead of dots while when used in the main functions, dots were used.

Change of scenery

The solution for this issue was found by Nathan. A library in C++ allows a user to change the locale and we could therefore set the locale so that stod wouldn’t cause a problem with the conversion. From that point, everything worked like it was supposed to.

Leave a Reply

Your email address will not be published. Required fields are marked *