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

Fix locale-dependent string-to-float conversion when loading Collada meshes #1684

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/rviz/mesh_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
peci1 marked this conversation as resolved.
Show resolved Hide resolved
ROS_WARN_STREAM("getMeshUnitRescale::Failed to convert <unit> element 'meter' attribute to "
"determine scaling. <unit> element: "
<< unitXml->GetText());
else
unit_scale = conversion_result;
}
}
}
Expand Down