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 918c1f1 commit 9405afb
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions ogre2/src/Ogre2GpuRays.cc
Original file line number Diff line number Diff line change
Expand Up @@ -602,50 +602,24 @@ void Ogre2GpuRays::Destroy()

auto engine = Ogre2RenderEngine::Instance();
auto ogreRoot = engine->OgreRoot();
auto textureGpuManager = ogreRoot->getRenderSystem()->getTextureGpuManager();
if (this->dataPtr->cubeUVTexture)
{
textureGpuManager->destroyTexture(this->dataPtr->cubeUVTexture);
this->dataPtr->cubeUVTexture = nullptr;
}
if (this->dataPtr->colorTexture)
{
textureGpuManager->destroyTexture(this->dataPtr->colorTexture);
this->dataPtr->colorTexture = nullptr;
}
if (this->dataPtr->depthTexture)
{
textureGpuManager->destroyTexture(this->dataPtr->depthTexture);
this->dataPtr->depthTexture = nullptr;
}
if (this->dataPtr->particleTexture)
{
textureGpuManager->destroyTexture(this->dataPtr->particleTexture);
this->dataPtr->particleTexture = nullptr;
}
if (this->dataPtr->particleDepthTexture)
{
textureGpuManager->destroyTexture(this->dataPtr->particleDepthTexture);
this->dataPtr->particleDepthTexture = 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;
}
}

// remove 2nd pass texture, material, compositor
Expand All @@ -662,6 +636,33 @@ void Ogre2GpuRays::Destroy()
this->dataPtr->ogreCompositorWorkspace2nd = nullptr;
}

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

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

0 comments on commit 9405afb

Please sign in to comment.