aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@jollamobile.com>2014-04-11 16:21:54 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-23 09:10:18 +0200
commit4e4228e0b1c01edada84d82746e3360aeffeb037 (patch)
treef39531393885e6940c6e4940f202c1a40a104f13
parent964dcdfb7bc106696b4be12b7f71ba52f8448973 (diff)
Support shutting down the render thread without an OpenGL context.
[ChangeLog][QtQuick][SceneGraph] There might not be an OpenGL context bound when QQuickWindow::sceneGraphInvalidated() is emitted if an error occurs while cleaning up the scene graph (such as EGL_CONTEXT_LOST). This is according to the documentation, but has never occurred in practice before. Change-Id: I13dbfbb4b6d0d27fa42fcb8b54df16ea02284807 Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp10
-rw-r--r--src/quick/scenegraph/qsgthreadedrenderloop.cpp14
-rw-r--r--src/quick/scenegraph/util/qsgatlastexture.cpp6
3 files changed, 15 insertions, 15 deletions
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
index 04f2bc891b..791e06ece2 100644
--- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
+++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
@@ -836,10 +836,12 @@ static void qsg_wipeBatch(Batch *batch, QOpenGLFunctions *funcs)
Renderer::~Renderer()
{
- // Clean up batches and buffers
- for (int i=0; i<m_opaqueBatches.size(); ++i) qsg_wipeBatch(m_opaqueBatches.at(i), this);
- for (int i=0; i<m_alphaBatches.size(); ++i) qsg_wipeBatch(m_alphaBatches.at(i), this);
- for (int i=0; i<m_batchPool.size(); ++i) qsg_wipeBatch(m_batchPool.at(i), this);
+ if (QOpenGLContext::currentContext()) {
+ // Clean up batches and buffers
+ for (int i=0; i<m_opaqueBatches.size(); ++i) qsg_wipeBatch(m_opaqueBatches.at(i), this);
+ for (int i=0; i<m_alphaBatches.size(); ++i) qsg_wipeBatch(m_alphaBatches.at(i), this);
+ for (int i=0; i<m_batchPool.size(); ++i) qsg_wipeBatch(m_batchPool.at(i), this);
+ }
// The shadowtree
qDeleteAll(m_nodes.values());
diff --git a/src/quick/scenegraph/qsgthreadedrenderloop.cpp b/src/quick/scenegraph/qsgthreadedrenderloop.cpp
index 2135bbef38..7b01f64ee0 100644
--- a/src/quick/scenegraph/qsgthreadedrenderloop.cpp
+++ b/src/quick/scenegraph/qsgthreadedrenderloop.cpp
@@ -398,6 +398,7 @@ bool QSGRenderThread::event(QEvent *e)
QSG_RT_DEBUG(" - setting exit flag and invalidating GL");
invalidateOpenGL(wme->window, wme->inDestructor, wme->fallbackSurface);
active = gl;
+ Q_ASSERT_X(!wme->inDestructor || !active, "QSGRenderThread::invalidateOpenGL()", "Thread's active state is not set to false when shutting down");
if (sleeping)
stopEventProcessing = true;
} else {
@@ -462,11 +463,8 @@ void QSGRenderThread::invalidateOpenGL(QQuickWindow *window, bool inDestructor,
bool wipeGL = inDestructor || (wipeSG && !window->isPersistentOpenGLContext());
bool current = gl->makeCurrent(fallback ? static_cast<QSurface *>(fallback) : static_cast<QSurface *>(window));
- if (!current) {
-#ifndef QT_NO_DEBUG
- qWarning() << "Scene Graph failed to acquire GL context during cleanup";
-#endif
- return;
+ if (Q_UNLIKELY(!current)) {
+ QSG_RT_DEBUG(" - cleanup without an OpenGL context");
}
// The canvas nodes must be cleaned up regardless if we are in the destructor..
@@ -475,14 +473,16 @@ void QSGRenderThread::invalidateOpenGL(QQuickWindow *window, bool inDestructor,
dd->cleanupNodesOnShutdown();
} else {
QSG_RT_DEBUG(" - persistent SG, avoiding cleanup");
- gl->doneCurrent();
+ if (current)
+ gl->doneCurrent();
return;
}
sgrc->invalidate();
QCoreApplication::processEvents();
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
- gl->doneCurrent();
+ if (current)
+ gl->doneCurrent();
QSG_RT_DEBUG(" - invalidated scenegraph..");
if (wipeGL) {
diff --git a/src/quick/scenegraph/util/qsgatlastexture.cpp b/src/quick/scenegraph/util/qsgatlastexture.cpp
index 997d58de0f..99d1d60258 100644
--- a/src/quick/scenegraph/util/qsgatlastexture.cpp
+++ b/src/quick/scenegraph/util/qsgatlastexture.cpp
@@ -185,11 +185,9 @@ Atlas::~Atlas()
void Atlas::invalidate()
{
- Q_ASSERT(QOpenGLContext::currentContext());
- if (m_texture_id) {
+ if (m_texture_id && QOpenGLContext::currentContext())
glDeleteTextures(1, &m_texture_id);
- m_texture_id = 0;
- }
+ m_texture_id = 0;
}
Texture *Atlas::create(const QImage &image)