Skip to content

Commit b9a3d4b

Browse files
author
Jani Hautakangas
committed
Fix to QGLWidget crash
QGLWidget crashed due to regression caused by fix to QTTH-1553. Crash only occurred if application was locked to landscape mode but started when device was in portrait mode. Task-number: QTTH-1597 Reviewed-by: Laszlo Agocs
1 parent 17e0607 commit b9a3d4b

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

src/opengl/qgl.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4297,16 +4297,19 @@ bool QGLWidget::event(QEvent *e)
42974297
// if we've reparented a window that has the current context
42984298
// bound, we need to rebind that context to the new window id
42994299
if (d->glcx == QGLContext::currentContext())
4300-
makeCurrent();
4300+
makeCurrent(); // Shouldn't happen but keep it here just for sure
43014301

43024302
if (testAttribute(Qt::WA_TranslucentBackground))
43034303
setContext(new QGLContext(d->glcx->requestedFormat(), this));
43044304
}
43054305

43064306
// A re-parent is likely to destroy the Symbian window and re-create it. It is important
43074307
// that we free the EGL surface _before_ the winID changes - otherwise we can leak.
4308-
if (e->type() == QEvent::ParentAboutToChange)
4308+
if (e->type() == QEvent::ParentAboutToChange) {
4309+
if (d->glcx == QGLContext::currentContext())
4310+
d->glcx->doneCurrent();
43094311
d->glcx->d_func()->destroyEglSurfaceForDevice();
4312+
}
43104313

43114314
if ((e->type() == QEvent::ParentChange) || (e->type() == QEvent::WindowStateChange)) {
43124315
// The window may have been re-created during re-parent or state change - if so, the EGL

src/opengl/qgl_p.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class QGLWidgetPrivate : public QWidgetPrivate
175175
#endif
176176
#if defined(Q_OS_SYMBIAN)
177177
, eglSurfaceWindowId(0)
178+
, surfaceSizeInitialized(false)
178179
#endif
179180
{
180181
isGLWidget = 1;
@@ -220,6 +221,7 @@ class QGLWidgetPrivate : public QWidgetPrivate
220221
#ifdef Q_OS_SYMBIAN
221222
void recreateEglSurface();
222223
WId eglSurfaceWindowId;
224+
bool surfaceSizeInitialized : 1;
223225
#endif
224226
};
225227

src/opengl/qgl_symbian.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) // almost same as
259259
return true;
260260
}
261261

262-
void QGLWidget::resizeEvent(QResizeEvent *)
262+
void QGLWidget::resizeEvent(QResizeEvent *e)
263263
{
264264
Q_D(QGLWidget);
265265
if (!isValid())
@@ -270,17 +270,18 @@ void QGLWidget::resizeEvent(QResizeEvent *)
270270
if (this == qt_gl_share_widget())
271271
return;
272272

273-
if (QGLContext::currentContext())
274-
doneCurrent();
275-
276-
// Symbian needs to recreate the surface on resize.
277-
d->recreateEglSurface();
273+
if (!d->surfaceSizeInitialized || e->oldSize() != e->size()) {
274+
// On Symbian we need to recreate the surface on resize.
275+
d->recreateEglSurface();
276+
d->surfaceSizeInitialized = true;
277+
}
278278

279279
makeCurrent();
280+
280281
if (!d->glcx->initialized())
281282
glInit();
283+
282284
resizeGL(width(), height());
283-
//handle overlay
284285
}
285286

286287
const QGLContext* QGLWidget::overlayContext() const
@@ -363,6 +364,9 @@ void QGLWidgetPrivate::recreateEglSurface()
363364
WId currentId = q->winId();
364365

365366
if (glcx->d_func()->eglSurface != EGL_NO_SURFACE) {
367+
if (glcx == QGLContext::currentContext())
368+
glcx->doneCurrent();
369+
366370
eglDestroySurface(glcx->d_func()->eglContext->display(),
367371
glcx->d_func()->eglSurface);
368372
}

0 commit comments

Comments
 (0)