Skip to content

Commit d07c0c6

Browse files
authored
Fix memory corruption in Ogre2GpuRays (Garden) (#788)
* Fix memory corruption in Ogre2GpuRays Order of destruction was inverted Signed-off-by: Matias N. Goldberg <[email protected]>
1 parent 918c1f1 commit d07c0c6

File tree

1 file changed

+32
-33
lines changed

1 file changed

+32
-33
lines changed

ogre2/src/Ogre2GpuRays.cc

+32-33
Original file line numberDiff line numberDiff line change
@@ -603,56 +603,29 @@ void Ogre2GpuRays::Destroy()
603603
auto engine = Ogre2RenderEngine::Instance();
604604
auto ogreRoot = engine->OgreRoot();
605605
auto textureGpuManager = ogreRoot->getRenderSystem()->getTextureGpuManager();
606-
if (this->dataPtr->cubeUVTexture)
607-
{
608-
textureGpuManager->destroyTexture(this->dataPtr->cubeUVTexture);
609-
this->dataPtr->cubeUVTexture = nullptr;
610-
}
611-
if (this->dataPtr->colorTexture)
612-
{
613-
textureGpuManager->destroyTexture(this->dataPtr->colorTexture);
614-
this->dataPtr->colorTexture = nullptr;
615-
}
616-
if (this->dataPtr->depthTexture)
617-
{
618-
textureGpuManager->destroyTexture(this->dataPtr->depthTexture);
619-
this->dataPtr->depthTexture = nullptr;
620-
}
621-
if (this->dataPtr->particleTexture)
622-
{
623-
textureGpuManager->destroyTexture(this->dataPtr->particleTexture);
624-
this->dataPtr->particleTexture = nullptr;
625-
}
626-
if (this->dataPtr->particleDepthTexture)
627-
{
628-
textureGpuManager->destroyTexture(this->dataPtr->particleDepthTexture);
629-
this->dataPtr->particleDepthTexture = nullptr;
630-
}
631606

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

634609
// remove 1st pass textures, material, compositors
635610
for (auto i : this->dataPtr->cubeFaceIdx)
636611
{
637-
if (this->dataPtr->firstPassTextures[i])
638-
{
639-
ogreRoot->getRenderSystem()->getTextureGpuManager()->destroyTexture(
640-
this->dataPtr->firstPassTextures[i]);
641-
this->dataPtr->firstPassTextures[i] = nullptr;
642-
}
643612
if (this->dataPtr->ogreCompositorWorkspace1st[i])
644613
{
645614
ogreCompMgr->removeWorkspace(
646615
this->dataPtr->ogreCompositorWorkspace1st[i]);
647616
this->dataPtr->ogreCompositorWorkspace1st[i] = nullptr;
648617
}
618+
if (this->dataPtr->firstPassTextures[i])
619+
{
620+
textureGpuManager->destroyTexture(this->dataPtr->firstPassTextures[i]);
621+
this->dataPtr->firstPassTextures[i] = nullptr;
622+
}
649623
}
650624

651625
// remove 2nd pass texture, material, compositor
652626
if (this->dataPtr->secondPassTexture)
653627
{
654-
ogreRoot->getRenderSystem()->getTextureGpuManager()->destroyTexture(
655-
this->dataPtr->secondPassTexture);
628+
textureGpuManager->destroyTexture(this->dataPtr->secondPassTexture);
656629
this->dataPtr->secondPassTexture = nullptr;
657630
}
658631

@@ -662,6 +635,32 @@ void Ogre2GpuRays::Destroy()
662635
this->dataPtr->ogreCompositorWorkspace2nd = nullptr;
663636
}
664637

638+
if (this->dataPtr->cubeUVTexture)
639+
{
640+
textureGpuManager->destroyTexture(this->dataPtr->cubeUVTexture);
641+
this->dataPtr->cubeUVTexture = nullptr;
642+
}
643+
if (this->dataPtr->colorTexture)
644+
{
645+
textureGpuManager->destroyTexture(this->dataPtr->colorTexture);
646+
this->dataPtr->colorTexture = nullptr;
647+
}
648+
if (this->dataPtr->depthTexture)
649+
{
650+
textureGpuManager->destroyTexture(this->dataPtr->depthTexture);
651+
this->dataPtr->depthTexture = nullptr;
652+
}
653+
if (this->dataPtr->particleTexture)
654+
{
655+
textureGpuManager->destroyTexture(this->dataPtr->particleTexture);
656+
this->dataPtr->particleTexture = nullptr;
657+
}
658+
if (this->dataPtr->particleDepthTexture)
659+
{
660+
textureGpuManager->destroyTexture(this->dataPtr->particleDepthTexture);
661+
this->dataPtr->particleDepthTexture = nullptr;
662+
}
663+
665664
if (this->scene)
666665
{
667666
Ogre::SceneManager *ogreSceneManager = this->scene->OgreSceneManager();

0 commit comments

Comments
 (0)