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

Add null checks when loading example render engine #156

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 17 additions & 2 deletions examples/hello_world_plugin/HelloWorldPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,55 @@ namespace mock
// Documentation Inherited.
public: virtual std::string Name() const override
{
return "test2";
return "HelloWorldPlugin";
}

// Documentation Inherited.
protected: virtual bool LoadImpl(const std::map<std::string, std::string> &_params) override
{
return true;
}

/// \brief Initialize the render engine.
/// \return True if the operation is successful
protected: virtual bool InitImpl() override
{
return true;
}

/// \brief Get a pointer to the list of scenes managed by the render
/// engine.
/// \return list of scenes
protected: virtual ignition::rendering::SceneStorePtr Scenes() const override
{
return nullptr;
}

/// \brief Create a scene.
/// \param[in] _id Unique scene Id
/// \parampin] _name Name of scene
protected: virtual ignition::rendering::ScenePtr CreateSceneImpl(unsigned int _id,
const std::string &_name) override
{
return nullptr;
}

/// \brief Singelton setup.
private: friend class ignition::common::SingletonT<HelloWorldRenderEngine>;
};

class HelloWorldPlugin :
public ignition::rendering::RenderEnginePlugin
{
/// \brief Get the name of the render engine loaded by this plugin.
/// \return Name of render engine
public: std::string Name() const
{
return "test";
return HelloWorldRenderEngine::Instance()->Name();
}

/// \brief Get a pointer to the render engine loaded by this plugin.
/// \return Render engine instance
public: ignition::rendering::RenderEngine *Engine() const
{
return HelloWorldRenderEngine::Instance();
Expand Down
22 changes: 22 additions & 0 deletions examples/hello_world_plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,25 @@ This will generate the `HelloWorldPlugin` library under `build`.
The exact name of the library file depends on the operating system
such as `libHelloWorldPlugin.so` on Linux, `libHelloWorldPlugin.dylib` on macOS,
and `HelloWorldPlugin.dll` on Windows.

## Run

Be sure to have the `IGN_GAZEBO_RENDER_ENGINE_PATH` environment variable set to the path
where your plugin is located. From within the `build` directory of this example, you can run

~~~
export IGN_GAZEBO_RENDER_ENGINE_PATH=$PWD
~~~

to set the environment variable accordingly.


Now you can run `ign gazebo` with the name of the resultant library file (without the `lib` prefix
or the file extension, i.e., libHelloWorldPlugin.so -> HelloWorldPlugin):

~~~
ign gazebo --render-engine HelloWorldPlugin
~~~

You should see a blank screen within the Ignition GUI, as this mocked plugin provides no implementation
for the scene.
50 changes: 43 additions & 7 deletions src/base/BaseRenderEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,72 +94,108 @@ bool BaseRenderEngine::IsEnabled() const
//////////////////////////////////////////////////
unsigned int BaseRenderEngine::SceneCount() const
{
return this->Scenes()->Size();
auto scenes = this->Scenes();
if (scenes)
return scenes->Size();
return 0u;
}

//////////////////////////////////////////////////
bool BaseRenderEngine::HasScene(ConstScenePtr _scene) const
{
return this->Scenes()->Contains(_scene);
auto scenes = this->Scenes();
if (scenes)
return scenes->Contains(_scene);
return false;
}

//////////////////////////////////////////////////
bool BaseRenderEngine::HasSceneId(unsigned int _id) const
{
return this->Scenes()->ContainsId(_id);
auto scenes = this->Scenes();
if (scenes)
return scenes->ContainsId(_id);
return false;
}

//////////////////////////////////////////////////
bool BaseRenderEngine::HasSceneName(const std::string &_name) const
{
return this->Scenes()->ContainsName(_name);
auto scenes = this->Scenes();
if (scenes)
return scenes->ContainsName(_name);
return false;
}

//////////////////////////////////////////////////
ScenePtr BaseRenderEngine::SceneById(unsigned int _id) const
{
return this->Scenes()->GetById(_id);
auto scenes = this->Scenes();
if (scenes)
return scenes->GetById(_id);
return ScenePtr();
}

//////////////////////////////////////////////////
ScenePtr BaseRenderEngine::SceneByName(const std::string &_name) const
{
return this->Scenes()->GetByName(_name);
auto scenes = this->Scenes();
if (scenes)
return scenes->GetByName(_name);
return ScenePtr();
}

//////////////////////////////////////////////////
ScenePtr BaseRenderEngine::SceneByIndex(unsigned int _index) const
{
return this->Scenes()->GetByIndex(_index);
auto scenes = this->Scenes();
if (scenes)
return scenes->GetByIndex(_index);
return ScenePtr();
}

//////////////////////////////////////////////////
void BaseRenderEngine::DestroyScene(ScenePtr _scene)
{
auto scenes = this->Scenes();
if (!scenes)
return;
this->Scenes()->Destroy(_scene);
}

//////////////////////////////////////////////////
void BaseRenderEngine::DestroySceneById(unsigned int _id)
{
auto scenes = this->Scenes();
if (!scenes)
return;
this->Scenes()->DestroyById(_id);
}

//////////////////////////////////////////////////
void BaseRenderEngine::DestroySceneByName(const std::string &_name)
{
auto scenes = this->Scenes();
if (!scenes)
return;
this->Scenes()->DestroyByName(_name);
}

//////////////////////////////////////////////////
void BaseRenderEngine::DestroySceneByIndex(unsigned int _index)
{
auto scenes = this->Scenes();
if (!scenes)
return;
this->Scenes()->DestroyByIndex(_index);
}

//////////////////////////////////////////////////
void BaseRenderEngine::DestroyScenes()
{
auto scenes = this->Scenes();
if (!scenes)
return;
this->Scenes()->DestroyAll();
}

Expand Down