Skip to content

Commit

Permalink
Fix memory corruption in Ogre2GpuRays
Browse files Browse the repository at this point in the history
Order of destruction was inverted

Signed-off-by: Matias N. Goldberg <[email protected]>
  • Loading branch information
darksylinc committed Dec 11, 2022
1 parent e6c3b72 commit 07aa91b
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions ogre2/src/Ogre2GpuRays.cc
Original file line number Diff line number Diff line change
Expand Up @@ -407,30 +407,24 @@ void Ogre2GpuRays::Destroy()

auto engine = Ogre2RenderEngine::Instance();
auto ogreRoot = engine->OgreRoot();
if (this->dataPtr->cubeUVTexture)
{
ogreRoot->getRenderSystem()->getTextureGpuManager()->destroyTexture(
this->dataPtr->cubeUVTexture);
this->dataPtr->cubeUVTexture = nullptr;
}

Ogre::CompositorManager2 *ogreCompMgr = ogreRoot->getCompositorManager2();

// remove 1st pass textures, material, compositors
for (auto i : this->dataPtr->cubeFaceIdx)
{
if (this->dataPtr->firstPassTextures[i])
{
ogreRoot->getRenderSystem()->getTextureGpuManager()->destroyTexture(
this->dataPtr->firstPassTextures[i]);
this->dataPtr->firstPassTextures[i] = nullptr;
}
if (this->dataPtr->ogreCompositorWorkspace1st[i])
{
ogreCompMgr->removeWorkspace(
this->dataPtr->ogreCompositorWorkspace1st[i]);
this->dataPtr->ogreCompositorWorkspace1st[i] = nullptr;
}
if (this->dataPtr->firstPassTextures[i])
{
ogreRoot->getRenderSystem()->getTextureGpuManager()->destroyTexture(
this->dataPtr->firstPassTextures[i]);
this->dataPtr->firstPassTextures[i] = nullptr;
}
}
if (this->dataPtr->matFirstPass)
{
Expand Down Expand Up @@ -473,6 +467,13 @@ void Ogre2GpuRays::Destroy()
this->dataPtr->ogreCompositorWorkspaceDef2nd.clear();
}

auto textureGpuManager = ogreRoot->getRenderSystem()->getTextureGpuManager();
if (this->dataPtr->cubeUVTexture)
{
textureGpuManager->destroyTexture(this->dataPtr->cubeUVTexture);
this->dataPtr->cubeUVTexture = nullptr;
}

if (this->scene)
{
Ogre::SceneManager *ogreSceneManager = this->scene->OgreSceneManager();
Expand Down

0 comments on commit 07aa91b

Please sign in to comment.