diff --git a/src/RenderEngineManager.cc b/src/RenderEngineManager.cc index 54ba3a591..4504fdbc0 100644 --- a/src/RenderEngineManager.cc +++ b/src/RenderEngineManager.cc @@ -302,6 +302,18 @@ void RenderEngineManager::UnregisterEngine(const std::string &_name) std::lock_guard 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); diff --git a/test/common_test/RenderingIface_TEST.cc b/test/common_test/RenderingIface_TEST.cc index 1dbe27e1b..441141ad7 100644 --- a/test/common_test/RenderingIface_TEST.cc +++ b/test/common_test/RenderingIface_TEST.cc @@ -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