From ae486957e3ba582d9fedcdf3fc0c2a37bda13ae0 Mon Sep 17 00:00:00 2001 From: "Matias N. Goldberg" Date: Thu, 2 Jul 2020 01:08:30 -0300 Subject: [PATCH] [GL3+] Fix destruction of RenderTextures destroying regular Textures destroyInternalResourcesImpl was only being called from within GL3PlusTextureGpu's destructor. However it is a virtual call, and thus GL3PlusTextureGpuRenderTarget::destroyInternalResourcesImpl would never get called. This led GL3PlusTextureGpu::destroyInternalResourcesImpl to believe there is a regular Texture in mFinalTextureName, because derived class never got to zero it out. To trigger this scenario: * The RenderTexture had to be a depth buffer or be created with the NotTexture flag * The TextureGpu must be destroyed without having been transitioned to non-resident * A regular texture and a RenderTarget had both been asigned the same mFinalTextureName handle value (one is a glRenderbuffer, the other a glTexture) Although the conditions are hard to trigger, the fix for shared depth buffers leaking (#103) skyrocketed the likehood of encountering this bug --- RenderSystems/GL3Plus/include/OgreGL3PlusTextureGpu.h | 1 + RenderSystems/GL3Plus/src/OgreGL3PlusTextureGpu.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/RenderSystems/GL3Plus/include/OgreGL3PlusTextureGpu.h b/RenderSystems/GL3Plus/include/OgreGL3PlusTextureGpu.h index 5244afba5d7..9e31cb7fe57 100644 --- a/RenderSystems/GL3Plus/include/OgreGL3PlusTextureGpu.h +++ b/RenderSystems/GL3Plus/include/OgreGL3PlusTextureGpu.h @@ -147,6 +147,7 @@ namespace Ogre VaoManager *vaoManager, IdString name, uint32 textureFlags, TextureTypes::TextureTypes initialType, TextureGpuManager *textureManager ); + virtual ~GL3PlusTextureGpuRenderTarget(); virtual void _setDepthBufferDefaults( uint16 depthBufferPoolId, bool preferDepthTexture, PixelFormatGpu desiredDepthBufferFormat ); diff --git a/RenderSystems/GL3Plus/src/OgreGL3PlusTextureGpu.cpp b/RenderSystems/GL3Plus/src/OgreGL3PlusTextureGpu.cpp index 85e931b979a..04ea4debdcd 100644 --- a/RenderSystems/GL3Plus/src/OgreGL3PlusTextureGpu.cpp +++ b/RenderSystems/GL3Plus/src/OgreGL3PlusTextureGpu.cpp @@ -744,6 +744,11 @@ namespace Ogre mDepthBufferPoolId = 0; } //----------------------------------------------------------------------------------- + GL3PlusTextureGpuRenderTarget::~GL3PlusTextureGpuRenderTarget() + { + destroyInternalResourcesImpl(); + } + //----------------------------------------------------------------------------------- void GL3PlusTextureGpuRenderTarget::createInternalResourcesImpl(void) { if( mPixelFormat == PFG_NULL )