diff --git a/ogre/src/OgreCamera.cc b/ogre/src/OgreCamera.cc index caa64a4b9..3b7af1ef8 100644 --- a/ogre/src/OgreCamera.cc +++ b/ogre/src/OgreCamera.cc @@ -62,6 +62,14 @@ void OgreCamera::Destroy() this->ogreCamera = nullptr; } } + + if (this->selectionBuffer) + { + delete this->selectionBuffer; + this->selectionBuffer = nullptr; + } + + BaseCamera::Destroy(); } ////////////////////////////////////////////////// diff --git a/ogre/src/OgreGpuRays.cc b/ogre/src/OgreGpuRays.cc index 134ce6779..9b09b7903 100644 --- a/ogre/src/OgreGpuRays.cc +++ b/ogre/src/OgreGpuRays.cc @@ -238,6 +238,8 @@ void OgreGpuRays::Destroy() this->dataPtr->texIdx.clear(); this->dataPtr->texCount = 0u; + + BaseGpuRays::Destroy(); } ///////////////////////////////////////////////// diff --git a/ogre/src/OgreLightVisual.cc b/ogre/src/OgreLightVisual.cc index 642fc53ac..c1809ce7a 100644 --- a/ogre/src/OgreLightVisual.cc +++ b/ogre/src/OgreLightVisual.cc @@ -86,7 +86,6 @@ void OgreLightVisual::CreateVisual() this->dataPtr->line->AddPoint(p.X(), p.Y(), p.Z()); } this->dataPtr->line->Update(); - this->ogreNode->setVisible(true); } ////////////////////////////////////////////////// diff --git a/ogre/src/OgreSelectionBuffer.cc b/ogre/src/OgreSelectionBuffer.cc index c3d209abc..e1c580776 100644 --- a/ogre/src/OgreSelectionBuffer.cc +++ b/ogre/src/OgreSelectionBuffer.cc @@ -124,7 +124,10 @@ void OgreSelectionBuffer::DeleteRTTBuffer() this->dataPtr->buffer = nullptr; } if (this->dataPtr->pixelBox) + { delete this->dataPtr->pixelBox; + this->dataPtr->pixelBox = nullptr; + } } ///////////////////////////////////////////////// diff --git a/ogre/src/OgreThermalCamera.cc b/ogre/src/OgreThermalCamera.cc index e7569f39c..82e8d8ab2 100644 --- a/ogre/src/OgreThermalCamera.cc +++ b/ogre/src/OgreThermalCamera.cc @@ -346,6 +346,8 @@ void OgreThermalCamera::Destroy() this->ogreCamera = nullptr; } } + + BaseThermalCamera::Destroy(); } ////////////////////////////////////////////////// diff --git a/ogre/src/OgreWideAngleCamera.cc b/ogre/src/OgreWideAngleCamera.cc index 1869ff70c..b6e3ad3bc 100644 --- a/ogre/src/OgreWideAngleCamera.cc +++ b/ogre/src/OgreWideAngleCamera.cc @@ -37,9 +37,9 @@ #include "gz/rendering/ogre/OgreWideAngleCamera.hh" #include "gz/rendering/ogre/OgreConversions.hh" -#include "gz/rendering/ogre/OgreRTShaderSystem.hh" #include "gz/rendering/ogre/OgreRenderEngine.hh" #include "gz/rendering/ogre/OgreRenderPass.hh" +#include "gz/rendering/ogre/OgreRTShaderSystem.hh" /// \brief Private data for the WideAngleCamera class class gz::rendering::OgreWideAngleCamera::Implementation @@ -180,6 +180,9 @@ void OgreWideAngleCamera::PreRender() ////////////////////////////////////////////////// void OgreWideAngleCamera::Destroy() { + if (!this->dataPtr->ogreCamera) + return; + this->RemoveAllRenderPasses(); if (this->dataPtr->imageBuffer) @@ -218,6 +221,13 @@ void OgreWideAngleCamera::Destroy() } } + if (this->dataPtr->ogreCamera) + { + this->scene->OgreSceneManager()->destroyCamera( + this->dataPtr->ogreCamera->getName()); + this->dataPtr->ogreCamera = nullptr; + } + if (this->dataPtr->envCubeMapTexture) { Ogre::TextureManager::getSingleton().remove( @@ -240,6 +250,7 @@ void OgreWideAngleCamera::Destroy() } this->DestroyRenderTexture(); + BaseWideAngleCamera::Destroy(); } ////////////////////////////////////////////////// diff --git a/ogre2/include/gz/rendering/ogre2/Ogre2Heightmap.hh b/ogre2/include/gz/rendering/ogre2/Ogre2Heightmap.hh index f611afc01..0aa9c5496 100644 --- a/ogre2/include/gz/rendering/ogre2/Ogre2Heightmap.hh +++ b/ogre2/include/gz/rendering/ogre2/Ogre2Heightmap.hh @@ -96,9 +96,7 @@ namespace gz public: void UpdateForRender(Ogre::Camera *_activeCamera); // Documentation inherited. - // \todo(iche033) rename this to Destroy and - // make this function public and virtual - private: void DestroyImpl(); + public: virtual void Destroy() override; /// \brief Heightmap should only be created by scene. private: friend class OgreScene; diff --git a/ogre2/src/CMakeLists.txt b/ogre2/src/CMakeLists.txt index 5fb68de75..c2cd9f479 100644 --- a/ogre2/src/CMakeLists.txt +++ b/ogre2/src/CMakeLists.txt @@ -15,10 +15,12 @@ set(engine_name "ogre2") gz_add_component(${engine_name} SOURCES ${sources} GET_TARGET_NAME ogre2_target) +set(OGRE2_RESOURCE_PATH_STR "${OGRE2_RESOURCE_PATH}") +string(REPLACE ";" ":" OGRE2_RESOURCE_PATH_STR "${OGRE2_RESOURCE_PATH}") set_property( SOURCE Ogre2RenderEngine.cc PROPERTY COMPILE_DEFINITIONS - OGRE2_RESOURCE_PATH="${OGRE2_RESOURCE_PATH}" + OGRE2_RESOURCE_PATH="${OGRE2_RESOURCE_PATH_STR}" OGRE2_VERSION="${OGRE2_VERSION}" ) diff --git a/ogre2/src/Ogre2Camera.cc b/ogre2/src/Ogre2Camera.cc index 50449ac47..7cdb7c8fb 100644 --- a/ogre2/src/Ogre2Camera.cc +++ b/ogre2/src/Ogre2Camera.cc @@ -72,6 +72,14 @@ void Ogre2Camera::Destroy() ogreSceneManager->destroyCamera(this->ogreCamera); this->ogreCamera = nullptr; } + + if (this->selectionBuffer) + { + delete this->selectionBuffer; + this->selectionBuffer = nullptr; + } + + BaseCamera::Destroy(); } ////////////////////////////////////////////////// diff --git a/ogre2/src/Ogre2DepthCamera.cc b/ogre2/src/Ogre2DepthCamera.cc index a18aace52..4fc173b7b 100644 --- a/ogre2/src/Ogre2DepthCamera.cc +++ b/ogre2/src/Ogre2DepthCamera.cc @@ -360,6 +360,8 @@ void Ogre2DepthCamera::Destroy() this->ogreCamera = nullptr; } } + + BaseDepthCamera::Destroy(); } ////////////////////////////////////////////////// diff --git a/ogre2/src/Ogre2Heightmap.cc b/ogre2/src/Ogre2Heightmap.cc index 19dad926f..fadd8a315 100644 --- a/ogre2/src/Ogre2Heightmap.cc +++ b/ogre2/src/Ogre2Heightmap.cc @@ -76,6 +76,13 @@ Ogre2Heightmap::Ogre2Heightmap(const HeightmapDescriptor &_desc) ////////////////////////////////////////////////// Ogre2Heightmap::~Ogre2Heightmap() { + this->Destroy(); +} + +////////////////////////////////////////////////// +void Ogre2Heightmap::Destroy() +{ + this->dataPtr->terra.reset(); } ////////////////////////////////////////////////// diff --git a/ogre2/src/Ogre2RayQuery.cc b/ogre2/src/Ogre2RayQuery.cc index a9b9a03b9..29b3c2db2 100644 --- a/ogre2/src/Ogre2RayQuery.cc +++ b/ogre2/src/Ogre2RayQuery.cc @@ -88,6 +88,16 @@ Ogre2RayQuery::Ogre2RayQuery() ////////////////////////////////////////////////// Ogre2RayQuery::~Ogre2RayQuery() { + if (this->dataPtr->rayQuery) + { + Ogre2ScenePtr ogreScene = + std::dynamic_pointer_cast(this->Scene()); + if (ogreScene) + { + ogreScene->OgreSceneManager()->destroyQuery(this->dataPtr->rayQuery); + this->dataPtr->rayQuery = nullptr; + } + } } ////////////////////////////////////////////////// diff --git a/ogre2/src/Ogre2RenderEngine.cc b/ogre2/src/Ogre2RenderEngine.cc index c33e85d5f..4c0b76f9b 100644 --- a/ogre2/src/Ogre2RenderEngine.cc +++ b/ogre2/src/Ogre2RenderEngine.cc @@ -149,11 +149,17 @@ Ogre2RenderEngine::Ogre2RenderEngine() : this->dummyWindowId = 0; std::string ogrePath = std::string(OGRE2_RESOURCE_PATH); - this->ogrePaths.push_back(ogrePath); + std::vector paths = common::split(ogrePath, ":"); + for (const auto &path : paths) + this->ogrePaths.push_back(path); const char *env = std::getenv("OGRE2_RESOURCE_PATH"); if (env) - this->ogrePaths.push_back(std::string(env)); + { + paths = common::split(std::string(env), ":"); + for (const auto &path : paths) + this->ogrePaths.push_back(path); + } } ////////////////////////////////////////////////// diff --git a/ogre2/src/Ogre2SegmentationCamera.cc b/ogre2/src/Ogre2SegmentationCamera.cc index 6b8853f76..ef0c4e106 100644 --- a/ogre2/src/Ogre2SegmentationCamera.cc +++ b/ogre2/src/Ogre2SegmentationCamera.cc @@ -155,6 +155,8 @@ void Ogre2SegmentationCamera::Destroy() } this->dataPtr->materialSwitcher.reset(); + + BaseCamera::Destroy(); } ///////////////////////////////////////////////// diff --git a/ogre2/src/Ogre2SelectionBuffer.cc b/ogre2/src/Ogre2SelectionBuffer.cc index 7a67877d5..29942dcee 100644 --- a/ogre2/src/Ogre2SelectionBuffer.cc +++ b/ogre2/src/Ogre2SelectionBuffer.cc @@ -208,11 +208,19 @@ void Ogre2SelectionBuffer::DeleteRTTBuffer() this->dataPtr->ogreCompositorWorkspace = nullptr; } - auto engine = Ogre2RenderEngine::Instance(); - auto ogreRoot = engine->OgreRoot(); - ogreRoot->getRenderSystem()->getTextureGpuManager()->destroyTexture( - this->dataPtr->renderTexture); - this->dataPtr->renderTexture = nullptr; + if (this->dataPtr->renderTexture) + { + auto engine = Ogre2RenderEngine::Instance(); + auto ogreRoot = engine->OgreRoot(); + Ogre::TextureGpuManager *textureMgr = + ogreRoot->getRenderSystem()->getTextureGpuManager(); + if (textureMgr->findTextureNoThrow( + this->dataPtr->renderTexture->getName())) + { + textureMgr->destroyTexture(this->dataPtr->renderTexture); + this->dataPtr->renderTexture = nullptr; + } + } } ///////////////////////////////////////////////// diff --git a/ogre2/src/Ogre2ThermalCamera.cc b/ogre2/src/Ogre2ThermalCamera.cc index 5cf35865d..11f2d5bcd 100644 --- a/ogre2/src/Ogre2ThermalCamera.cc +++ b/ogre2/src/Ogre2ThermalCamera.cc @@ -782,6 +782,8 @@ void Ogre2ThermalCamera::Destroy() } this->dataPtr->thermalMaterialSwitcher.reset(); + + BaseThermalCamera::Destroy(); } //////////////////////////////////////////////////