Skip to content

Commit

Permalink
World::LoadModel: avoid creating empty links
Browse files Browse the repository at this point in the history
The logic in World::LoadModel currently creates an empty
link in models without links by calling GetElement("link")
without checking if such an element exists. This checks
HasElement("link") before calling GetElement, which fixes
a nested model test.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
  • Loading branch information
scpeters committed May 26, 2022
1 parent 8f7e3f5 commit b29d38c
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions gazebo/physics/World.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1259,29 +1259,32 @@ ModelPtr World::LoadModel(sdf::ElementPtr _sdf , BasePtr _parent)
}
}

sdf::ElementPtr linkElem = _sdf->GetElement("link");
if (linkElem->HasElement("visual") &&
linkElem->GetElement("visual")->HasElement("material"))
if (_sdf->HasElement("link"))
{
sdf::ElementPtr matElem = linkElem->GetElement("visual")->
GetElement("material");

if (matElem->HasElement("shininess"))
{
this->dataPtr->materialShininessMap[modelName] =
matElem->Get<double>("shininess");
}
else
sdf::ElementPtr linkElem = _sdf->GetElement("link");
if (linkElem->HasElement("visual") &&
linkElem->GetElement("visual")->HasElement("material"))
{
this->dataPtr->materialShininessMap[modelName] = 0;
}
sdf::ElementPtr matElem = linkElem->GetElement("visual")->
GetElement("material");

std::string materialShininessService("/" + modelName + "/shininess");
if (!this->dataPtr->ignNode.Advertise(materialShininessService,
&World::MaterialShininessService, this))
{
gzerr << "Error advertising service ["
<< materialShininessService << "]" << std::endl;
if (matElem->HasElement("shininess"))
{
this->dataPtr->materialShininessMap[modelName] =
matElem->Get<double>("shininess");
}
else
{
this->dataPtr->materialShininessMap[modelName] = 0;
}

std::string materialShininessService("/" + modelName + "/shininess");
if (!this->dataPtr->ignNode.Advertise(materialShininessService,
&World::MaterialShininessService, this))
{
gzerr << "Error advertising service ["
<< materialShininessService << "]" << std::endl;
}
}
}

Expand Down

0 comments on commit b29d38c

Please sign in to comment.