From 076440704009ee7566f02fe95a36a16ce4e2fab3 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 23 Mar 2015 11:57:32 +0100 Subject: Avoid crashing in the vao when not supported The stored context pointer has to be reset to null in destroy() even when no VAO was created (vao is null). Otherwise destroying the context that was stored in the VAO will not lead to resetting the stored pointer, and a subsequent destruction of the VAO object will try to dereference it. Task-number: QTBUG-44562 Change-Id: I438bb3954d4bbd8b8d8704f6087479804f0073a7 Reviewed-by: Giuseppe D'Angelo Reviewed-by: Sean Harmer --- src/gui/opengl/qopenglvertexarrayobject.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/gui/opengl') diff --git a/src/gui/opengl/qopenglvertexarrayobject.cpp b/src/gui/opengl/qopenglvertexarrayobject.cpp index 6b0f2fede7..2a1b7f4bf4 100644 --- a/src/gui/opengl/qopenglvertexarrayobject.cpp +++ b/src/gui/opengl/qopenglvertexarrayobject.cpp @@ -189,11 +189,16 @@ bool QOpenGLVertexArrayObjectPrivate::create() void QOpenGLVertexArrayObjectPrivate::destroy() { + Q_Q(QOpenGLVertexArrayObject); + + if (context) { + QObject::disconnect(context, SIGNAL(aboutToBeDestroyed()), q, SLOT(_q_contextAboutToBeDestroyed())); + context = 0; + } + if (!vao) return; - Q_Q(QOpenGLVertexArrayObject); - switch (vaoFuncsType) { #ifndef QT_OPENGL_ES_2 case Core_3_2: @@ -212,10 +217,6 @@ void QOpenGLVertexArrayObjectPrivate::destroy() break; } - Q_ASSERT(context); - QObject::disconnect(context, SIGNAL(aboutToBeDestroyed()), q, SLOT(_q_contextAboutToBeDestroyed())); - context = 0; - vao = 0; } -- cgit v1.2.3 From 52781f2a7d4c63990c2484b267614450f80c5591 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 24 Mar 2015 16:57:23 +0100 Subject: Make versioned OpenGL functions working with the subclass pattern QOpenGLFunctions allows both deriving from it and getting an instance via QOpenGLContext::functions(). Unsurprisingly a large number of users attempt to use the versioned function wrappers in the same way. Unfortunately this approach was not that well supported. Besides some potential base class exporting issues the real blocker for QOpenGLWidget - or any versionfunction subclass whose associated context changes during its lifetime - is that the functions instances could only be initialized once. Unlike instances retrieved via QOpenGLContext::versionFunctions(), instances created "manually" were not deinitialized upon the destruction of the associated context because context did not know about them. A pattern like initializeOpenGLFunctions(); delete context; create new context and make it current initializeOpenGLFunctions(); is working fine in QOpenGLFunctions-derived classes but not with the versioned ones. To overcome this, start registering such instances to the context too. QOpenGLContext::destroy() can then reset the internal state so a subsequent initializeOpenGLFunctions() will reinitialize properly instead of bailing out mistakenly thinking that everything is ready to use. Task-number: QTBUG-45199 Change-Id: Ia1420bcccb33c51508698b7a1b036c7544a66e74 Reviewed-by: Sean Harmer --- src/gui/opengl/qopenglversionfunctions.cpp | 26 ++++++++++++++++++++++++++ src/gui/opengl/qopenglversionfunctions.h | 13 ++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) (limited to 'src/gui/opengl') diff --git a/src/gui/opengl/qopenglversionfunctions.cpp b/src/gui/opengl/qopenglversionfunctions.cpp index f3f709c3f0..346a526054 100644 --- a/src/gui/opengl/qopenglversionfunctions.cpp +++ b/src/gui/opengl/qopenglversionfunctions.cpp @@ -67,6 +67,17 @@ void QAbstractOpenGLFunctionsPrivate::removeFunctionsBackend(QOpenGLContext *con context->removeFunctionsBackend(v); } +void QAbstractOpenGLFunctionsPrivate::insertExternalFunctions(QOpenGLContext *context, QAbstractOpenGLFunctions *f) +{ + Q_ASSERT(context); + context->insertExternalFunctions(f); +} + +void QAbstractOpenGLFunctionsPrivate::removeExternalFunctions(QOpenGLContext *context, QAbstractOpenGLFunctions *f) +{ + Q_ASSERT(context); + context->removeExternalFunctions(f); +} /*! \class QAbstractOpenGLFunctions @@ -182,6 +193,9 @@ QAbstractOpenGLFunctions::QAbstractOpenGLFunctions() QAbstractOpenGLFunctions::~QAbstractOpenGLFunctions() { + Q_D(QAbstractOpenGLFunctions); + if (d->owningContext) + d->removeExternalFunctions(d->owningContext, this); delete d_ptr; } @@ -191,6 +205,18 @@ bool QAbstractOpenGLFunctions::initializeOpenGLFunctions() { Q_D(QAbstractOpenGLFunctions); d->initialized = true; + + // For a subclass whose instance is not created via + // QOpenGLContext::versionFunctions() owningContext is not set. Set it now + // and register such instances to the context as external ones. These are + // not owned by the context but still need certain cleanup when the context + // is destroyed. + if (!d->owningContext) { + d->owningContext = QOpenGLContext::currentContext(); + if (d->owningContext) + d->insertExternalFunctions(d->owningContext, this); + } + return true; } diff --git a/src/gui/opengl/qopenglversionfunctions.h b/src/gui/opengl/qopenglversionfunctions.h index 2ae0f429e5..fcf665f97e 100644 --- a/src/gui/opengl/qopenglversionfunctions.h +++ b/src/gui/opengl/qopenglversionfunctions.h @@ -114,6 +114,8 @@ public: QAtomicInt refs; }; +class QAbstractOpenGLFunctions; + class QAbstractOpenGLFunctionsPrivate { public: @@ -128,12 +130,16 @@ public: const QOpenGLVersionStatus &v, QOpenGLVersionFunctionsBackend *backend); static void removeFunctionsBackend(QOpenGLContext *context, const QOpenGLVersionStatus &v); + static void insertExternalFunctions(QOpenGLContext *context, QAbstractOpenGLFunctions *f); + static void removeExternalFunctions(QOpenGLContext *context, QAbstractOpenGLFunctions *f); + + static QAbstractOpenGLFunctionsPrivate *get(QAbstractOpenGLFunctions *q); QOpenGLContext *owningContext; bool initialized; }; -class QAbstractOpenGLFunctions +class Q_GUI_EXPORT QAbstractOpenGLFunctions { public: virtual ~QAbstractOpenGLFunctions(); @@ -154,6 +160,11 @@ protected: friend class QOpenGLContext; }; +inline QAbstractOpenGLFunctionsPrivate *QAbstractOpenGLFunctionsPrivate::get(QAbstractOpenGLFunctions *q) +{ + return q->d_func(); +} + #if !defined(QT_OPENGL_ES_2) class QOpenGLFunctions_1_0_CoreBackend : public QOpenGLVersionFunctionsBackend -- cgit v1.2.3 From a68b03d6a9828cd4a060db42a744e7df5a00bb07 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 25 Mar 2015 14:50:03 +0100 Subject: Fix qdoc warning in qopengltexture.cpp. qtbase/src/gui/opengl/qopengltexture.cpp:3652: warning: Cannot find 'ComparisonFunction' specified with '\enum' in any header file Change-Id: I92e808310f2d775cda30c1f1b6aaf0ed739b02f1 Reviewed-by: Laszlo Agocs --- src/gui/opengl/qopengltexture.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui/opengl') diff --git a/src/gui/opengl/qopengltexture.cpp b/src/gui/opengl/qopengltexture.cpp index fa4b6cdab0..9bc9926b70 100644 --- a/src/gui/opengl/qopengltexture.cpp +++ b/src/gui/opengl/qopengltexture.cpp @@ -3650,7 +3650,7 @@ QOpenGLTexture::DepthStencilMode QOpenGLTexture::depthStencilMode() const } /*! - \enum ComparisonFunction + \enum QOpenGLTexture::ComparisonFunction \since 5.5 This enum specifies which comparison operator is used when texture comparison is enabled on this texture. -- cgit v1.2.3