From 91e2c5d749e38eed93e91b14151faa549e70080f Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Mon, 18 Nov 2013 08:53:13 +0100 Subject: Safeguard QQuickWindow::hide() against other GL contexts. If another GL context is bound to another surface on the GUI thread, we can run into issues while cleaning up the SG nodes. Task-number: QTBUG-34898 Change-Id: Ifa02b7cdbc7ab38b3a149a21452cc5071498a7d1 Reviewed-by: Laszlo Agocs --- tests/auto/quick/scenegraph/tst_scenegraph.cpp | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests/auto/quick/scenegraph/tst_scenegraph.cpp') diff --git a/tests/auto/quick/scenegraph/tst_scenegraph.cpp b/tests/auto/quick/scenegraph/tst_scenegraph.cpp index 3b79f01f12..780d5a97db 100644 --- a/tests/auto/quick/scenegraph/tst_scenegraph.cpp +++ b/tests/auto/quick/scenegraph/tst_scenegraph.cpp @@ -58,6 +58,8 @@ private slots: void render_data(); void render(); + + void hideWithOtherContext(); }; template class ScopedList : public QList { @@ -401,6 +403,40 @@ void tst_SceneGraph::render() } } +// Testcase for QTBUG-34898. We make another context current on another surface +// in the GUI thread and hide the QQuickWindow while the other context is +// current on the other window. +void tst_SceneGraph::hideWithOtherContext() +{ + QWindow window; + window.setSurfaceType(QWindow::OpenGLSurface); + window.resize(100, 100); + window.create(); + QOpenGLContext context; + context.create(); + bool renderingOnMainThread = false; + + { + QQuickView view; + view.setSource(QUrl::fromLocalFile("data/simple.qml")); + view.setResizeMode(QQuickView::SizeViewToRootObject); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + renderingOnMainThread = view.openglContext()->thread() == QGuiApplication::instance()->thread(); + + // Make the local context current on the local window... + context.makeCurrent(&window); + } + + // The local context should no longer be the current one. It is not + // rebound because all well behaving Qt/OpenGL applications are + // required to makeCurrent their context again before making any + // GL calls to a new frame (see QOpenGLContext docs). + QVERIFY(!renderingOnMainThread || QOpenGLContext::currentContext() != &context); +} + + #include "tst_scenegraph.moc" QTEST_MAIN(tst_SceneGraph) -- cgit v1.2.3