diff --git a/ogre/src/OgreDistortionPass.cc b/ogre/src/OgreDistortionPass.cc index 160a81f2d..74722de6e 100644 --- a/ogre/src/OgreDistortionPass.cc +++ b/ogre/src/OgreDistortionPass.cc @@ -444,6 +444,21 @@ void OgreDistortionPass::Destroy() this->dataPtr->distortionInstance = nullptr; this->dataPtr->distortionCompositorListener.reset(); } + + if (!this->dataPtr->distortionMaterial.isNull()) + { + Ogre::MaterialManager &matManager = Ogre::MaterialManager::getSingleton(); + matManager.remove(this->dataPtr->distortionMaterial->getName()); + this->dataPtr->distortionMaterial.setNull(); + } + + if (!this->dataPtr->distortionTexture.isNull()) + { + auto &textureManager = Ogre::TextureManager::getSingleton(); + textureManager.unload(this->dataPtr->distortionTexture->getName()); + textureManager.remove(this->dataPtr->distortionTexture->getName()); + this->dataPtr->distortionTexture.setNull(); + } } ////////////////////////////////////////////////// diff --git a/ogre2/include/gz/rendering/ogre2/Ogre2LensFlarePass.hh b/ogre2/include/gz/rendering/ogre2/Ogre2LensFlarePass.hh index 81eb90c75..dd2181354 100644 --- a/ogre2/include/gz/rendering/ogre2/Ogre2LensFlarePass.hh +++ b/ogre2/include/gz/rendering/ogre2/Ogre2LensFlarePass.hh @@ -78,6 +78,9 @@ namespace gz public: void WorkspaceRemoved( Ogre::CompositorWorkspace *_workspace) override; + // Documentation inherited + public: virtual void Destroy() override; + /// \brief Check to see if the lens flare is occluded and return a scaling /// factor that is proportional to the lens flare's visibility /// \remark Ogre2LensFlarePass::PreRender must have been called first. diff --git a/ogre2/src/Ogre2LensFlarePass.cc b/ogre2/src/Ogre2LensFlarePass.cc index 17918b308..8f913dc92 100644 --- a/ogre2/src/Ogre2LensFlarePass.cc +++ b/ogre2/src/Ogre2LensFlarePass.cc @@ -126,6 +126,14 @@ Ogre2LensFlarePass::Ogre2LensFlarePass() : ////////////////////////////////////////////////// Ogre2LensFlarePass::~Ogre2LensFlarePass() { + this->Destroy(); +} + +////////////////////////////////////////////////// +void Ogre2LensFlarePass::Destroy() +{ + this->dataPtr->rayQuery.reset(); + this->dataPtr->currentCamera.reset(); } ////////////////////////////////////////////////// diff --git a/ogre2/src/Ogre2Material.cc b/ogre2/src/Ogre2Material.cc index 464158028..ab543915a 100644 --- a/ogre2/src/Ogre2Material.cc +++ b/ogre2/src/Ogre2Material.cc @@ -151,7 +151,12 @@ Ogre2Material::~Ogre2Material() void Ogre2Material::Destroy() { if (!this->Scene()->IsInitialized()) + { + // just reset the ogre pointers and return. + this->dataPtr->ogreSolidColorMat.reset(); + this->dataPtr->ogreSolidColorShader.reset(); return; + } if (!this->ogreDatablock) return; diff --git a/ogre2/src/Ogre2RayQuery.cc b/ogre2/src/Ogre2RayQuery.cc index 29b3c2db2..ae7bd3e4d 100644 --- a/ogre2/src/Ogre2RayQuery.cc +++ b/ogre2/src/Ogre2RayQuery.cc @@ -88,6 +88,9 @@ Ogre2RayQuery::Ogre2RayQuery() ////////////////////////////////////////////////// Ogre2RayQuery::~Ogre2RayQuery() { + if (!this->Scene()->IsInitialized()) + return; + if (this->dataPtr->rayQuery) { Ogre2ScenePtr ogreScene = diff --git a/ogre2/src/Ogre2SelectionBuffer.cc b/ogre2/src/Ogre2SelectionBuffer.cc index 29942dcee..e83cc768d 100644 --- a/ogre2/src/Ogre2SelectionBuffer.cc +++ b/ogre2/src/Ogre2SelectionBuffer.cc @@ -144,6 +144,9 @@ Ogre2SelectionBuffer::Ogre2SelectionBuffer(const std::string &_cameraName, ///////////////////////////////////////////////// Ogre2SelectionBuffer::~Ogre2SelectionBuffer() { + if (!this->dataPtr->scene || !this->dataPtr->scene->IsInitialized()) + return; + this->DeleteRTTBuffer(); // remove selectionMaterial in destructor @@ -157,7 +160,14 @@ Ogre2SelectionBuffer::~Ogre2SelectionBuffer() } // remove selection buffer camera - this->dataPtr->sceneMgr->destroyCamera(this->dataPtr->selectionCamera); + if (this->dataPtr->selectionCamera) + { + this->dataPtr->selectionCamera->removeListener( + this->dataPtr->materialSwitcher.get()); + this->dataPtr->sceneMgr->destroyCamera(this->dataPtr->selectionCamera); + this->dataPtr->selectionCamera = nullptr; + this->dataPtr->materialSwitcher.reset(); + } } /////////////////////////////////////////////////