From b01226625882d5e2696c9bc6dbe595bef3b67223 Mon Sep 17 00:00:00 2001 From: binary1248 Date: Fri, 18 May 2018 01:29:53 +0200 Subject: [PATCH] Fixed RenderTextureImplFBO's destructor incorrectly triggering deletion of other RenderTextureImplFBOs' active FBOs even when the context they reside in isn't being destroyed. --- src/SFML/Graphics/RenderTextureImplFBO.cpp | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/SFML/Graphics/RenderTextureImplFBO.cpp b/src/SFML/Graphics/RenderTextureImplFBO.cpp index 301aa043..4a4f1f62 100644 --- a/src/SFML/Graphics/RenderTextureImplFBO.cpp +++ b/src/SFML/Graphics/RenderTextureImplFBO.cpp @@ -53,6 +53,23 @@ namespace // Mutex to protect both active and stale frame buffer sets sf::Mutex mutex; + // This function is called either when a RenderTextureImplFBO is + // destroyed or via contextDestroyCallback when context destruction + // might trigger deletion of its contained stale FBOs + void destroyStaleFBOs() + { + sf::Uint64 contextId = sf::Context::getActiveContextId(); + + for (std::set >::iterator iter = staleFrameBuffers.begin(); iter != staleFrameBuffers.end(); ++iter) + { + if (iter->first == contextId) + { + GLuint frameBuffer = static_cast(iter->second); + glCheck(GLEXT_glDeleteFramebuffers(1, &frameBuffer)); + } + } + } + // Callback that is called every time a context is destroyed void contextDestroyCallback(void* arg) { @@ -79,14 +96,7 @@ namespace } // Destroy stale frame buffer objects - for (std::set >::iterator iter = staleFrameBuffers.begin(); iter != staleFrameBuffers.end(); ++iter) - { - if (iter->first == contextId) - { - GLuint frameBuffer = static_cast(iter->second); - glCheck(GLEXT_glDeleteFramebuffers(1, &frameBuffer)); - } - } + destroyStaleFBOs(); } } @@ -150,7 +160,7 @@ RenderTextureImplFBO::~RenderTextureImplFBO() staleFrameBuffers.insert(std::make_pair(iter->first, iter->second)); // Clean up FBOs - contextDestroyCallback(0); + destroyStaleFBOs(); // Delete the backup context if we had to create one delete m_context;