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

Clean up internal resources on Destroy #886

Merged
merged 2 commits into from
Aug 28, 2023
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
15 changes: 15 additions & 0 deletions ogre/src/OgreDistortionPass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

//////////////////////////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions ogre2/include/gz/rendering/ogre2/Ogre2LensFlarePass.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions ogre2/src/Ogre2LensFlarePass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ Ogre2LensFlarePass::Ogre2LensFlarePass() :
//////////////////////////////////////////////////
Ogre2LensFlarePass::~Ogre2LensFlarePass()
{
this->Destroy();
}

//////////////////////////////////////////////////
void Ogre2LensFlarePass::Destroy()
{
this->dataPtr->rayQuery.reset();
this->dataPtr->currentCamera.reset();
}

//////////////////////////////////////////////////
Expand Down
5 changes: 5 additions & 0 deletions ogre2/src/Ogre2Material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions ogre2/src/Ogre2RayQuery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ Ogre2RayQuery::Ogre2RayQuery()
//////////////////////////////////////////////////
Ogre2RayQuery::~Ogre2RayQuery()
{
if (!this->Scene()->IsInitialized())
return;

if (this->dataPtr->rayQuery)
{
Ogre2ScenePtr ogreScene =
Expand Down
12 changes: 11 additions & 1 deletion ogre2/src/Ogre2SelectionBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
/////////////////////////////////////////////////
Ogre2SelectionBuffer::~Ogre2SelectionBuffer()
{
if (!this->dataPtr->scene || !this->dataPtr->scene->IsInitialized())
return;

Check warning on line 148 in ogre2/src/Ogre2SelectionBuffer.cc

View check run for this annotation

Codecov / codecov/patch

ogre2/src/Ogre2SelectionBuffer.cc#L148

Added line #L148 was not covered by tests

this->DeleteRTTBuffer();

// remove selectionMaterial in destructor
Expand All @@ -157,7 +160,14 @@
}

// 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();
}
}

/////////////////////////////////////////////////
Expand Down