From c0f8f4749fab1e09a0432e71744b8230231eea36 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Wed, 30 Sep 2020 21:52:12 -0700 Subject: [PATCH 1/3] add null checks Signed-off-by: Ian Chen --- src/base/BaseRenderEngine.cc | 50 +++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/src/base/BaseRenderEngine.cc b/src/base/BaseRenderEngine.cc index bc5047f12..2a47f74c3 100644 --- a/src/base/BaseRenderEngine.cc +++ b/src/base/BaseRenderEngine.cc @@ -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(); } From 9da842e9e484d8d5d1ee80ec6849b79df9942ff0 Mon Sep 17 00:00:00 2001 From: John Shepherd Date: Thu, 1 Oct 2020 01:01:14 -0700 Subject: [PATCH 2/3] Add docs and readme explanation Signed-off-by: John Shepherd --- .../hello_world_plugin/HelloWorldPlugin.cc | 19 +++++++++++++++-- examples/hello_world_plugin/README.md | 21 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/examples/hello_world_plugin/HelloWorldPlugin.cc b/examples/hello_world_plugin/HelloWorldPlugin.cc index e47dbbdee..bc1e82082 100644 --- a/examples/hello_world_plugin/HelloWorldPlugin.cc +++ b/examples/hello_world_plugin/HelloWorldPlugin.cc @@ -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 &_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; }; 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(); diff --git a/examples/hello_world_plugin/README.md b/examples/hello_world_plugin/README.md index 29e7362bb..c8f9a09da 100644 --- a/examples/hello_world_plugin/README.md +++ b/examples/hello_world_plugin/README.md @@ -19,3 +19,24 @@ 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 `.so` 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. From 7a3172a3cb522fff3f1bedb2918bbfa1342602da Mon Sep 17 00:00:00 2001 From: John Shepherd Date: Thu, 1 Oct 2020 01:03:00 -0700 Subject: [PATCH 3/3] Update readme Signed-off-by: John Shepherd --- examples/hello_world_plugin/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/hello_world_plugin/README.md b/examples/hello_world_plugin/README.md index c8f9a09da..5f81c8215 100644 --- a/examples/hello_world_plugin/README.md +++ b/examples/hello_world_plugin/README.md @@ -31,8 +31,9 @@ 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 `.so` file extension, i.e., libHelloWorldPlugin.so -> HelloWorldPlugin): +or the file extension, i.e., libHelloWorldPlugin.so -> HelloWorldPlugin): ~~~ ign gazebo --render-engine HelloWorldPlugin