From 44b6bb3560b24ca665140b071a3d11d63ad14c5d Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Thu, 17 Nov 2011 16:06:27 +0100 Subject: [PATCH] Call invalidateResource() on QOpenGLMultiGroupSharedResource-owned resources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 202127f860208c21145e05685bc54219e1655dbd ensured that QOpenGLMultiGroupSharedResource-owned resources are deleted, but it was missing a call to invalidateResource(). Change-Id: I166ce8a7298772408081331fe1a91bd2cd88aebb Reviewed-by: Samuel Rødal --- src/gui/kernel/qopenglcontext.cpp | 1 + src/gui/kernel/qopenglcontext_p.h | 1 + tests/auto/gui/qopengl/tst_qopengl.cpp | 39 ++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index 88925df606..3549f647b5 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -595,6 +595,7 @@ void QOpenGLMultiGroupSharedResource::cleanup(QOpenGLContextGroup *group, QOpenG #ifdef QT_GL_CONTEXT_RESOURCE_DEBUG qDebug("Cleaning up context group resource %p, for group %p in thread %p.", this, group, QThread::currentThread()); #endif + value->invalidateResource(); value->free(); active.deref(); diff --git a/src/gui/kernel/qopenglcontext_p.h b/src/gui/kernel/qopenglcontext_p.h index 1a47d293e5..aff1042c5b 100644 --- a/src/gui/kernel/qopenglcontext_p.h +++ b/src/gui/kernel/qopenglcontext_p.h @@ -80,6 +80,7 @@ private: friend class QOpenGLContextGroup; friend class QOpenGLContextGroupPrivate; + friend class QOpenGLMultiGroupSharedResource; Q_DISABLE_COPY(QOpenGLSharedResource); }; diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index a3e0cf4fba..aa3e70a047 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -57,6 +57,7 @@ Q_OBJECT private slots: void sharedResourceCleanup(); void multiGroupSharedResourceCleanup(); + void multiGroupSharedResourceCleanupCustom(); void fboSimpleRendering(); void fboRendering(); void fboHandleNulledAfterContextDestroyed(); @@ -91,22 +92,32 @@ struct SharedResource : public QOpenGLSharedResource { } + SharedResource(QOpenGLContext *ctx) + : QOpenGLSharedResource(ctx->shareGroup()) + , resource(1) + , tracker(0) + { + } + ~SharedResource() { - tracker->destructorCalls++; + if (tracker) + tracker->destructorCalls++; } void invalidateResource() { resource = 0; - tracker->invalidateResourceCalls++; + if (tracker) + tracker->invalidateResourceCalls++; } void freeResource(QOpenGLContext *context) { Q_ASSERT(context == QOpenGLContext::currentContext()); resource = 0; - tracker->freeResourceCalls++; + if (tracker) + tracker->freeResourceCalls++; } int resource; @@ -195,6 +206,28 @@ void tst_QOpenGL::multiGroupSharedResourceCleanup() // Shouldn't crash when application exits. } +void tst_QOpenGL::multiGroupSharedResourceCleanupCustom() +{ + QWindow window; + window.setGeometry(0, 0, 10, 10); + window.create(); + + QOpenGLContext *ctx = new QOpenGLContext(); + ctx->create(); + ctx->makeCurrent(&window); + + QOpenGLMultiGroupSharedResource multiGroupSharedResource; + SharedResource *resource = multiGroupSharedResource.value(ctx); + SharedResourceTracker tracker; + resource->tracker = &tracker; + + delete ctx; + + QCOMPARE(tracker.invalidateResourceCalls, 1); + QCOMPARE(tracker.freeResourceCalls, 0); + QCOMPARE(tracker.destructorCalls, 1); +} + static bool fuzzyComparePixels(const QRgb testPixel, const QRgb refPixel, const char* file, int line, int x = -1, int y = -1) { static int maxFuzz = 1;