From bb774b559cd663a39c01013901a7520bec9087e6 Mon Sep 17 00:00:00 2001 From: Martin Pecka Date: Wed, 24 Nov 2021 10:51:55 +0100 Subject: [PATCH 1/2] Fix locale-dependent string-to-float conversion when loading Collada meshes --- src/rviz/mesh_loader.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/rviz/mesh_loader.cpp b/src/rviz/mesh_loader.cpp index 33171863bf..f56f34c44c 100644 --- a/src/rviz/mesh_loader.cpp +++ b/src/rviz/mesh_loader.cpp @@ -630,11 +630,19 @@ float getMeshUnitRescale(const std::string& resource_path) tinyxml2::XMLElement* unitXml = assetXml->FirstChildElement("unit"); if (unitXml && unitXml->Attribute("meter")) { + // Convert attribute meter to a float in a locale-independent manner + std::string unit_scale_str(unitXml->Attribute("meter")); + std::istringstream stream(unit_scale_str); + stream.imbue(std::locale::classic()); + float conversion_result; + stream >> conversion_result; // Failing to convert leaves unit_scale as the default. - if (unitXml->QueryFloatAttribute("meter", &unit_scale) != 0) - ROS_WARN_STREAM("getMeshUnitRescale::Failed to convert unit element meter attribute to " - "determine scaling. unit element: " + if (stream.fail() || !stream.eof()) + ROS_WARN_STREAM("getMeshUnitRescale::Failed to convert element 'meter' attribute to " + "determine scaling. element: " << unitXml->GetText()); + else + unit_scale = conversion_result; } } } From 3f690f29d662e10077da0cba1da845089767dc0d Mon Sep 17 00:00:00 2001 From: Martin Pecka Date: Wed, 24 Nov 2021 13:42:00 +0100 Subject: [PATCH 2/2] Fixed formatting --- src/rviz/mesh_loader.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rviz/mesh_loader.cpp b/src/rviz/mesh_loader.cpp index f56f34c44c..326e44e87d 100644 --- a/src/rviz/mesh_loader.cpp +++ b/src/rviz/mesh_loader.cpp @@ -638,11 +638,15 @@ float getMeshUnitRescale(const std::string& resource_path) stream >> conversion_result; // Failing to convert leaves unit_scale as the default. if (stream.fail() || !stream.eof()) + { ROS_WARN_STREAM("getMeshUnitRescale::Failed to convert element 'meter' attribute to " "determine scaling. element: " << unitXml->GetText()); + } else + { unit_scale = conversion_result; + } } } }