summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgl/tst_qgl.cpp
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-10-01 03:02:49 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-10-01 03:17:04 (GMT)
commit69e8fd3359a72230d377513b0314e64b5b83b712 (patch)
treee5318295a62d12254d16deaeb6b42b718bad9d93 /tests/auto/qgl/tst_qgl.cpp
parente8fc662c4b5a0fa5da6f0d47e1dbb5b2640d7001 (diff)
downloadQt-69e8fd3359a72230d377513b0314e64b5b83b712.zip
Qt-69e8fd3359a72230d377513b0314e64b5b83b712.tar.gz
Qt-69e8fd3359a72230d377513b0314e64b5b83b712.tar.bz2
Make QGLFramebufferObject crash-proof if QGLContext destroyed first
Sometimes it isn't possible to arrange for the QGLFramebufferObject to be destroyed before the QGLContext group in which it was created. Especially during application shutdown or in applications with multiple shared contexts. This change modifies QGLFramebufferObject to use QGLSharedResourceGuard, which ensures that when the last QGLContext in a sharing group is destroyed, any remaining FBO's will revert to !isValid(). It is now safe to destroy the context before the FBO, or the FBO before the context. Unit test included. Reviewed-by: Sarah Smith
Diffstat (limited to 'tests/auto/qgl/tst_qgl.cpp')
-rw-r--r--tests/auto/qgl/tst_qgl.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp
index 999d119..8027e9b 100644
--- a/tests/auto/qgl/tst_qgl.cpp
+++ b/tests/auto/qgl/tst_qgl.cpp
@@ -84,6 +84,7 @@ private slots:
void testDontCrashOnDanglingResources();
void replaceClipping();
void clipTest();
+ void destroyFBOAfterContext();
};
tst_QGL::tst_QGL()
@@ -1720,6 +1721,33 @@ void tst_QGL::clipTest()
QCOMPARE(widgetFB, reference);
}
+void tst_QGL::destroyFBOAfterContext()
+{
+ if (!QGLFramebufferObject::hasOpenGLFramebufferObjects())
+ QSKIP("QGLFramebufferObject not supported on this platform", SkipSingle);
+
+ QGLWidget *glw = new QGLWidget();
+ glw->makeCurrent();
+
+ // No multisample with combined depth/stencil attachment:
+ QGLFramebufferObjectFormat fboFormat;
+ fboFormat.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
+
+ // Don't complicate things by using NPOT:
+ QGLFramebufferObject *fbo = new QGLFramebufferObject(256, 128, fboFormat);
+
+ // The handle should be valid until the context is destroyed.
+ QVERIFY(fbo->handle() != 0);
+ QVERIFY(fbo->isValid());
+
+ delete glw;
+
+ // The handle should now be zero.
+ QVERIFY(fbo->handle() == 0);
+ QVERIFY(!fbo->isValid());
+
+ delete fbo;
+}
QTEST_MAIN(tst_QGL)
#include "tst_qgl.moc"