Call invalidateResource() on QOpenGLMultiGroupSharedResource-owned resources

Commit 202127f860 ensured that
QOpenGLMultiGroupSharedResource-owned resources are deleted,
but it was missing a call to invalidateResource().

Change-Id: I166ce8a7298772408081331fe1a91bd2cd88aebb
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
This commit is contained in:
Kent Hansen 2011-11-17 16:06:27 +01:00 committed by Qt by Nokia
parent 1b681bbd0f
commit 44b6bb3560
3 changed files with 38 additions and 3 deletions

View File

@ -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();

View File

@ -80,6 +80,7 @@ private:
friend class QOpenGLContextGroup;
friend class QOpenGLContextGroupPrivate;
friend class QOpenGLMultiGroupSharedResource;
Q_DISABLE_COPY(QOpenGLSharedResource);
};

View File

@ -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<SharedResource>(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;