Skip to content

Commit

Permalink
Fix plugin conversion error message (#2094)
Browse files Browse the repository at this point in the history
This fixes the error

[Err] [Conversions.cc:1791] Tried to convert SDF [world] into [plugin]

The error comes from AddSystem passing an sdf::ElementPtr that corresponds to a <world> tag instead of a <plugin> tag when it's optional _sdf element is empty, which occurs mostly in tests when AddSystem is used to add Relay plugin which doesn't have an associated SDFormat file.


---------

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
  • Loading branch information
azeey authored Aug 25, 2023
1 parent 30eeb62 commit 46c5df3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/SimulationRunner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,23 @@ void SimulationRunner::PublishStats()
this->rootClockPub.Publish(clockMsg);
}

namespace {

// Create an sdf::ElementPtr that corresponds to an empty `<plugin>` element.
sdf::ElementPtr createEmptyPluginElement()
{
auto plugin = std::make_shared<sdf::Element>();
sdf::initFile("plugin.sdf", plugin);
return plugin;
}
}
//////////////////////////////////////////////////
void SimulationRunner::AddSystem(const SystemPluginPtr &_system,
std::optional<Entity> _entity,
std::optional<std::shared_ptr<const sdf::Element>> _sdf)
{
auto entity = _entity.value_or(worldEntity(this->entityCompMgr));
auto sdf = _sdf.value_or(this->sdfWorld->Element());
auto sdf = _sdf.value_or(createEmptyPluginElement());
this->systemMgr->AddSystem(_system, entity, sdf);
}

Expand All @@ -470,7 +480,7 @@ void SimulationRunner::AddSystem(
std::optional<std::shared_ptr<const sdf::Element>> _sdf)
{
auto entity = _entity.value_or(worldEntity(this->entityCompMgr));
auto sdf = _sdf.value_or(this->sdfWorld->Element());
auto sdf = _sdf.value_or(createEmptyPluginElement());
this->systemMgr->AddSystem(_system, entity, sdf);
}

Expand Down
2 changes: 1 addition & 1 deletion src/TestFixture_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TestFixtureTest : public InternalFixture<::testing::Test>
EXPECT_EQ(worldEntity, _entity);

ASSERT_NE(nullptr, _sdf);
EXPECT_EQ("world", _sdf->GetName());
EXPECT_EQ("plugin", _sdf->GetName());

EXPECT_NE(kNullEntity, _ecm.EntityByComponents(components::Name("box")));
EXPECT_NE(kNullEntity, _ecm.EntityByComponents(components::Name("sphere")));
Expand Down

0 comments on commit 46c5df3

Please sign in to comment.