From 78169378e68f08d7b7273e37cd5b84e7b3a82e25 Mon Sep 17 00:00:00 2001 From: darksylinc Date: Mon, 28 Jun 2021 19:21:35 -0300 Subject: [PATCH] Do not crash on shutdown (#355) - ogreRoot may be nullptr - Do not destroy textures already scheduled for destruction Signed-off-by: Matias N. Goldberg --- ogre2/src/Ogre2RenderEngine.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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?