diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-09-08 09:23:34 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-09-22 14:15:29 +0000 |
commit | eecc351c5d05989c1b0ea3349f76a579b83eb446 (patch) | |
tree | e3a6fd57da7756a02a3127f9efabff0f203fb356 | |
parent | 9e81fb4df6809bb2ff909af595ac9e2487760181 (diff) |
Null out QOpenGLContext::screen upon screen disconnect
Returning a dangling pointer is no good. Do what QOffscreenSurface does:
just null it out.
Task-number: QTBUG-42803
Change-Id: I01a6db9ae8974a1c78157ebc67097c8dac3a6b6e
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
-rw-r--r-- | src/gui/kernel/qopenglcontext.cpp | 16 | ||||
-rw-r--r-- | src/gui/kernel/qopenglcontext.h | 2 | ||||
-rw-r--r-- | src/gui/kernel/qopenglcontext_p.h | 2 |
3 files changed, 18 insertions, 2 deletions
diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index 9e5767658f..85d05959de 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -462,8 +462,7 @@ QPlatformOpenGLContext *QOpenGLContext::shareHandle() const QOpenGLContext::QOpenGLContext(QObject *parent) : QObject(*new QOpenGLContextPrivate(), parent) { - Q_D(QOpenGLContext); - d->screen = QGuiApplication::primaryScreen(); + setScreen(QGuiApplication::primaryScreen()); } /*! @@ -499,9 +498,20 @@ void QOpenGLContext::setShareContext(QOpenGLContext *shareContext) void QOpenGLContext::setScreen(QScreen *screen) { Q_D(QOpenGLContext); + if (d->screen) + disconnect(d->screen, SIGNAL(destroyed(QObject*)), this, SLOT(_q_screenDestroyed(QObject*))); d->screen = screen; if (!d->screen) d->screen = QGuiApplication::primaryScreen(); + if (d->screen) + connect(d->screen, SIGNAL(destroyed(QObject*)), this, SLOT(_q_screenDestroyed(QObject*))); +} + +void QOpenGLContextPrivate::_q_screenDestroyed(QObject *object) +{ + Q_Q(QOpenGLContext); + if (object == static_cast<QObject *>(screen)) + q->setScreen(0); } /*! @@ -1626,4 +1636,6 @@ void QOpenGLMultiGroupSharedResource::cleanup(QOpenGLContextGroup *group, QOpenG m_groups.removeOne(group); } +#include "moc_qopenglcontext.cpp" + QT_END_NAMESPACE diff --git a/src/gui/kernel/qopenglcontext.h b/src/gui/kernel/qopenglcontext.h index 85e7abfa26..841967a545 100644 --- a/src/gui/kernel/qopenglcontext.h +++ b/src/gui/kernel/qopenglcontext.h @@ -241,6 +241,8 @@ private: void setTextureFunctions(QOpenGLTextureHelper* textureFuncs); void destroy(); + + Q_PRIVATE_SLOT(d_func(), void _q_screenDestroyed(QObject *object)) }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qopenglcontext_p.h b/src/gui/kernel/qopenglcontext_p.h index f9f3ce2c5f..4a746bf12b 100644 --- a/src/gui/kernel/qopenglcontext_p.h +++ b/src/gui/kernel/qopenglcontext_p.h @@ -270,6 +270,8 @@ public: static QHash<QOpenGLContext *, bool> makeCurrentTracker; static QMutex makeCurrentTrackerMutex; #endif + + void _q_screenDestroyed(QObject *object); }; Q_GUI_EXPORT void qt_gl_set_global_share_context(QOpenGLContext *context); |