QOpenGLContextGroup::~QOpenGLContextGroup()
{
Q_D(QOpenGLContextGroup);
-
- QList<QOpenGLSharedResource *>::iterator it = d->m_sharedResources.begin();
- QList<QOpenGLSharedResource *>::iterator end = d->m_sharedResources.end();
-
- while (it != end) {
- (*it)->invalidateResource();
- (*it)->m_group = 0;
- ++it;
- }
-
- qDeleteAll(d->m_pendingDeletion.begin(), d->m_pendingDeletion.end());
+ d->cleanup();
}
QList<QOpenGLContext *> QOpenGLContextGroup::shares() const
if (ctx == m_context && !m_shares.isEmpty())
m_context = m_shares.first();
- if (!m_refs.deref())
+ if (!m_refs.deref()) {
+ cleanup();
q->deleteLater();
+ }
+}
+
+void QOpenGLContextGroupPrivate::cleanup()
+{
+ QList<QOpenGLSharedResource *>::iterator it = m_sharedResources.begin();
+ QList<QOpenGLSharedResource *>::iterator end = m_sharedResources.end();
+
+ while (it != end) {
+ (*it)->invalidateResource();
+ (*it)->m_group = 0;
+ ++it;
+ }
+
+ m_sharedResources.clear();
+
+ qDeleteAll(m_pendingDeletion.begin(), m_pendingDeletion.end());
+ m_pendingDeletion.clear();
}
void QOpenGLContextGroupPrivate::deletePendingResources(QOpenGLContext *ctx)
void addContext(QOpenGLContext *ctx);
void removeContext(QOpenGLContext *ctx);
+ void cleanup();
+
void deletePendingResources(QOpenGLContext *ctx);
QOpenGLContext *m_context;
QCOMPARE(tracker.freeResourceCalls, 1);
QCOMPARE(tracker.destructorCalls, 1);
+ tracker.reset();
+
+ resource = new SharedResource(&tracker);
+
+ // this should cause invalidateResource() to be called
delete ctx2;
+
+ QCOMPARE(tracker.invalidateResourceCalls, 1);
+ QCOMPARE(tracker.freeResourceCalls, 0);
+ QCOMPARE(tracker.destructorCalls, 0);
+
+ // should have no effect other than destroying the resource,
+ // as it has already been invalidated
+ resource->free();
+
+ 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)