Fix broken resource cleanup in QOpenGLWidget

The context has to be made current. Otherwise we may fail to clean up or,
what's worse, we may delete FBOs and textures in some random context.

The latter was visible with ANGLE in the qopenglwidget example. When having
two QOpenGLWidget instances, the context for the second happened to be the
current one when destroying the first. This is now avoided by making sure the
correct context is current when deleting the FBOs.

Task-number: QTBUG-42696
Change-Id: I8c1eed7c13a869968cc67141e585d02c6bc6f279
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
bb10
Laszlo Agocs 2014-11-17 10:13:14 +01:00
parent 2fb3941198
commit b00d4475aa
1 changed files with 10 additions and 0 deletions

View File

@ -578,12 +578,22 @@ GLuint QOpenGLWidgetPrivate::textureId() const
void QOpenGLWidgetPrivate::reset()
{
Q_Q(QOpenGLWidget);
// Destroy the OpenGL resources first. These need the context to be current.
if (initialized)
q->makeCurrent();
delete paintDevice;
paintDevice = 0;
delete fbo;
fbo = 0;
delete resolvedFbo;
resolvedFbo = 0;
if (initialized)
q->doneCurrent();
// Delete the context first, then the surface. Slots connected to
// the context's aboutToBeDestroyed() may still call makeCurrent()
// to perform some cleanup.