Skip to content

Commit

Permalink
Fix RenderingIface_TEST for ogre2 when there is no display (gazebosim…
Browse files Browse the repository at this point in the history
…#1098)

Signed-off-by: Ian Chen <[email protected]>
(cherry picked from commit 52ac1de)
  • Loading branch information
iche033 committed Jan 14, 2025
1 parent 6d02c15 commit 75b6aa3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/RenderEngineManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,18 @@ void RenderEngineManager::UnregisterEngine(const std::string &_name)
std::lock_guard<std::recursive_mutex> lock(this->dataPtr->enginesMutex);
auto iter = this->dataPtr->engines.find(_name);

if (iter == this->dataPtr->engines.end())
{
// Check if the provided name is a name of a default engine, if so,
// translate the name to the shared library name
auto defaultIt = this->dataPtr->defaultEngines.find(_name);
if (defaultIt != this->dataPtr->defaultEngines.end())
iter = this->dataPtr->engines.find(defaultIt->second);

if (iter == this->dataPtr->engines.end())
gzerr << "No render-engine registered with name: " << _name << std::endl;
}

if (iter != this->dataPtr->engines.end())
{
this->dataPtr->UnregisterEngine(iter);
Expand Down
11 changes: 8 additions & 3 deletions test/common_test/RenderingIface_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,19 @@ TEST(RenderingIfaceTest, RegisterEngine)
if (count == 0)
return;

// unregister existing engine by index
RenderEngine *eng = engine(0u);
RenderEngine *eng = nullptr;
std::string engineToTest = "";
if (gz::utils::env(kEngineToTestEnv, engineToTest))
eng = engine(engineToTest);
else
eng = engine(0u);

ASSERT_NE(nullptr, eng);
auto engineName = eng->Name();
ASSERT_FALSE(engineName.empty());

EXPECT_TRUE(hasEngine(engineName));
EXPECT_NO_THROW(unregisterEngine(0u));
EXPECT_NO_THROW(unregisterEngine(engineName));
EXPECT_FALSE(hasEngine(engineName));

// register engine back with a different name
Expand Down

0 comments on commit 75b6aa3

Please sign in to comment.