diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2016-12-07 14:59:43 +0000 |
---|---|---|
committer | Jani Heikkinen <jani.heikkinen@qt.io> | 2016-12-08 05:12:15 +0000 |
commit | 8a591a491278b76827057a51fa90ab5ee723bd75 (patch) | |
tree | 42e2ac1953465e6050b86f1ff5e7ea2d634fcda8 /src | |
parent | 08daecb93d275dca62c32f98a7d28ed02bc555e7 (diff) |
Ensure GL resources are released at renderer shutdown
Also taking care to handle Scene3D case where releaseGraphisResources()
may get called more than once.
Task-number: QTBUG-57496
Change-Id: I987a372ddfeb026c95a6b50a885c57687d294a00
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/render/backend/renderer.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/render/backend/renderer.cpp b/src/render/backend/renderer.cpp index 4176cdbb2..3e2070511 100644 --- a/src/render/backend/renderer.cpp +++ b/src/render/backend/renderer.cpp @@ -90,6 +90,7 @@ #include <Qt3DCore/private/aspectcommanddebugger_p.h> #include <QStack> +#include <QOffscreenSurface> #include <QSurface> #include <QElapsedTimer> #include <QLibraryInfo> @@ -327,12 +328,32 @@ void Renderer::shutdown() */ void Renderer::releaseGraphicsResources() { - // Clean up the graphics context and any resources - const QVector<GLTexture*> activeTextures = m_nodesManager->glTextureManager()->activeResources(); - for (GLTexture *tex : activeTextures) - tex->destroyGLTexture(); + // We may get called twice when running inside of a Scene3D. Once when Qt Quick + // wants to shutdown, and again when the render aspect gets unregistered. So + // check that we haven't already cleaned up before going any further. + if (!m_graphicsContext) + return; + + // Try to temporarily make the context current so we can free up any resources + QOpenGLContext *context = m_graphicsContext->openGLContext(); + Q_ASSERT(context); + QSurfaceFormat format = context->format(); + QOffscreenSurface offscreenSurface; + offscreenSurface.setFormat(format); + offscreenSurface.create(); + if (context->makeCurrent(&offscreenSurface)) { - // TO DO: Do the same thing with buffers + // Clean up the graphics context and any resources + const QVector<GLTexture*> activeTextures = m_nodesManager->glTextureManager()->activeResources(); + for (GLTexture *tex : activeTextures) + tex->destroyGLTexture(); + + // TO DO: Do the same thing with buffers + + context->doneCurrent(); + } else { + qWarning() << "Failed to make context current: OpenGL resources will not be destroyed"; + } m_graphicsContext.reset(nullptr); qCDebug(Backend) << Q_FUNC_INFO << "Renderer properly shutdown"; |