From 29778037f8a7b2c86bc4044409b37d5a51a15432 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Thu, 5 Apr 2018 12:54:01 +0100 Subject: Don't block on lost context When glGetError returns GL_CONTEXT_LOST, on XCB + Nvidia at least, the error does not get cleared until the next successful glGetGraphicsResetStatus. We can't handle this properly until the start of the next frame where we will hopefully have a valid context, but in the meantime we should avoid locking up completely. Change-Id: Id438d44d83b926e1f3e4281ca3704231bf1a23cf Reviewed-by: Allan Sandfeld Jensen --- src/gui/opengl/qopenglframebufferobject.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/gui/opengl') diff --git a/src/gui/opengl/qopenglframebufferobject.cpp b/src/gui/opengl/qopenglframebufferobject.cpp index 91c25184b6..83bc568ba7 100644 --- a/src/gui/opengl/qopenglframebufferobject.cpp +++ b/src/gui/opengl/qopenglframebufferobject.cpp @@ -55,12 +55,16 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_DEBUG #define QT_RESET_GLERROR() \ { \ - while (QOpenGLContext::currentContext()->functions()->glGetError() != GL_NO_ERROR) {} \ + while (true) {\ + GLenum error = QOpenGLContext::currentContext()->functions()->glGetError(); \ + if (error == GL_NO_ERROR || error == GL_CONTEXT_LOST) \ + break; \ + } \ } #define QT_CHECK_GLERROR() \ { \ GLenum err = QOpenGLContext::currentContext()->functions()->glGetError(); \ - if (err != GL_NO_ERROR) { \ + if (err != GL_NO_ERROR && err != GL_CONTEXT_LOST) { \ qDebug("[%s line %d] OpenGL Error: %d", \ __FILE__, __LINE__, (int)err); \ } \ @@ -126,6 +130,10 @@ QT_BEGIN_NAMESPACE #define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 #endif +#ifndef GL_CONTEXT_LOST +#define GL_CONTEXT_LOST 0x0507 +#endif + /*! \class QOpenGLFramebufferObjectFormat @@ -1303,8 +1311,11 @@ static QImage qt_gl_read_framebuffer(const QSize &size, GLenum internal_format, { QOpenGLContext *ctx = QOpenGLContext::currentContext(); QOpenGLFunctions *funcs = ctx->functions(); - while (funcs->glGetError()); - + while (true) { + GLenum error = funcs->glGetError(); + if (error == GL_NO_ERROR || error == GL_CONTEXT_LOST) + break; + } switch (internal_format) { case GL_RGB: case GL_RGB8: -- cgit v1.2.3