diff --git a/ogre2/src/Ogre2RenderEngine.cc b/ogre2/src/Ogre2RenderEngine.cc index 827855f61..bf15509ba 100644 --- a/ogre2/src/Ogre2RenderEngine.cc +++ b/ogre2/src/Ogre2RenderEngine.cc @@ -118,19 +118,19 @@ void Ogre2RenderEngine::Destroy() delete this->ogreOverlaySystem; this->ogreOverlaySystem = nullptr; - // Clean up any textures that may still be in flight. - Ogre::TextureGpuManager *mgr = + if (this->ogreRoot) + { + // Clean up any textures that may still be in flight. + Ogre::TextureGpuManager *mgr = this->ogreRoot->getRenderSystem()->getTextureGpuManager(); - auto entries = mgr->getEntries(); - for (auto& [name, entry] : entries) - { - if (entry.resourceGroup == "General") - mgr->destroyTexture(entry.texture); - } + auto entries = mgr->getEntries(); + for (auto& [name, entry] : entries) + { + if (entry.resourceGroup == "General" && !entry.destroyRequested) + mgr->destroyTexture(entry.texture); + } - if (this->ogreRoot) - { try { // TODO(anyone): do we need to catch segfault on delete?