From f7be841e43dde6af1194c370c6a50b0167dd89f4 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen <miikka.heikkinen@theqtcompany.com> Date: Mon, 11 Jan 2016 14:08:36 +0200 Subject: [PATCH] Fix context leak when destroying canvas that was never properly shown. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sharecontext gets created even if the canvas doesn't create the regular context, but it wasn't destroyed unless regular context also existed. Change-Id: Ib975ff65c4138000b4a2f1277fe56c9d5109c626 Task-number: QTBUG-50369 Reviewed-by: Tomi Korpipää <tomi.korpipaa@theqtcompany.com> Reviewed-by: Pasi Keränen <pasi.keranen@theqtcompany.com> --- src/imports/qtcanvas3d/canvasrenderer.cpp | 84 +++++++++++------------ 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/src/imports/qtcanvas3d/canvasrenderer.cpp b/src/imports/qtcanvas3d/canvasrenderer.cpp index 86ca838..7939c3b 100644 --- a/src/imports/qtcanvas3d/canvasrenderer.cpp +++ b/src/imports/qtcanvas3d/canvasrenderer.cpp @@ -315,64 +315,64 @@ void CanvasRenderer::init(QQuickWindow *window, const CanvasContextAttributes &c */ void CanvasRenderer::shutDown() { - if (!m_glContext) - return; - QMutexLocker locker(&m_shutdownMutex); - m_fps = 0; + if (m_glContext) { + if (m_renderTarget == Canvas::RenderTargetOffscreenBuffer) + m_glContext->makeCurrent(m_offscreenSurface); + + m_commandQueue.clearResourceMaps(); - if (m_renderTarget == Canvas::RenderTargetOffscreenBuffer) - m_glContext->makeCurrent(m_offscreenSurface); + deleteCommandData(); + m_executeQueue.clear(); - m_commandQueue.clearResourceMaps(); + delete m_renderFbo; + delete m_displayFbo; + delete m_antialiasFbo; - deleteCommandData(); - m_executeQueue.clear(); + if (m_renderTarget == Canvas::RenderTargetOffscreenBuffer) { + delete m_alphaMultiplierFbo; + m_alphaMultiplierFbo = 0; + glDeleteBuffers(1, &m_alphaMultiplierUVBuffer); + glDeleteBuffers(1, &m_alphaMultiplierVertexBuffer); + m_alphaMultiplierUVBuffer = 0; + m_alphaMultiplierVertexBuffer = 0; + delete m_alphaMultiplierProgram; + delete m_alphaMultiplierVertexShader; + delete m_alphaMultiplierFragmentShader; + m_alphaMultiplierProgram = 0; + m_alphaMultiplierVertexShader = 0; + m_alphaMultiplierFragmentShader = 0; - delete m_renderFbo; - delete m_displayFbo; - delete m_antialiasFbo; + m_glContext->doneCurrent(); + delete m_glContext; + } - if (m_renderTarget == Canvas::RenderTargetOffscreenBuffer) { - delete m_alphaMultiplierFbo; - m_alphaMultiplierFbo = 0; - glDeleteBuffers(1, &m_alphaMultiplierUVBuffer); - glDeleteBuffers(1, &m_alphaMultiplierVertexBuffer); - m_alphaMultiplierUVBuffer = 0; - m_alphaMultiplierVertexBuffer = 0; - delete m_alphaMultiplierProgram; - delete m_alphaMultiplierVertexShader; - delete m_alphaMultiplierFragmentShader; - m_alphaMultiplierProgram = 0; - m_alphaMultiplierVertexShader = 0; - m_alphaMultiplierFragmentShader = 0; + m_renderFbo = 0; + m_displayFbo = 0; + m_antialiasFbo = 0; - m_glContext->doneCurrent(); - delete m_glContext; - } + // m_offscreenSurface is owned by main thread, as on some platforms that is required. + if (m_offscreenSurface) { + m_offscreenSurface->deleteLater(); + m_offscreenSurface = 0; + } - m_renderFbo = 0; - m_displayFbo = 0; - m_antialiasFbo = 0; + m_currentFramebufferId = 0; + m_forceViewportRect = QRect(); - delete m_glContextShare; + delete m_stateStore; + m_stateStore = 0; - // m_offscreenSurface is owned by main thread, as on some platforms that is required. - if (m_offscreenSurface) { - m_offscreenSurface->deleteLater(); - m_offscreenSurface = 0; + m_glContext = 0; } - m_glContext = 0; + delete m_glContextShare; + m_glContextQt = 0; m_glContextShare = 0; - m_currentFramebufferId = 0; - m_forceViewportRect = QRect(); - - delete m_stateStore; - m_stateStore = 0; + m_fps = 0; } /*! -- GitLab