QGLWidget: Gracefully handle failed makeCurrent during resize and paint event

The underlying QOpenGLContext may fail to be made current, e.g. if the
surface is not exposed, or the graphics hardware is not available.

Instead of trying to initialize and resize the GL viewport with a
non-current context, we return early and defer the init and resize
until later.

Change-Id: I278ca8f1ad4d3da2d5be18b44d775f8d6c8af726
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Tor Arne Vestbø 2018-07-18 20:36:26 +02:00
parent 8c91070606
commit cc27a50ef8
2 changed files with 15 additions and 4 deletions

View File

@ -4084,7 +4084,13 @@ bool QGLWidget::isSharing() const
void QGLWidget::makeCurrent()
{
Q_D(QGLWidget);
d->glcx->makeCurrent();
d->makeCurrent();
}
bool QGLWidgetPrivate::makeCurrent()
{
glcx->makeCurrent();
return QGLContext::currentContext() == glcx;
}
/*!
@ -4422,7 +4428,8 @@ void QGLWidget::resizeEvent(QResizeEvent *e)
QWidget::resizeEvent(e);
if (!isValid())
return;
makeCurrent();
if (!d->makeCurrent())
return;
if (!d->glcx->initialized())
glInit();
const qreal scaleFactor = (window() && window()->windowHandle()) ?
@ -4537,7 +4544,8 @@ void QGLWidget::glInit()
Q_D(QGLWidget);
if (!isValid())
return;
makeCurrent();
if (!d->makeCurrent())
return;
initializeGL();
d->glcx->setInitialized(true);
}
@ -4555,7 +4563,8 @@ void QGLWidget::glDraw()
Q_D(QGLWidget);
if (!isValid())
return;
makeCurrent();
if (!d->makeCurrent())
return;
#ifndef QT_OPENGL_ES
if (d->glcx->deviceIsPixmap() && !d->glcx->contextHandle()->isOpenGLES())
qgl1_functions()->glDrawBuffer(GL_FRONT);

View File

@ -145,6 +145,8 @@ public:
glcx->reset();
}
bool makeCurrent();
QGLContext *glcx;
QGLWidgetGLPaintDevice glDevice;
bool autoSwap;