diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-05-13 17:48:42 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-05-15 20:12:26 +0000 |
commit | 9b36512b9453f429644b0c388d381f7a2fc0f825 (patch) | |
tree | e573f34053e3c15f9900bbe5c4a92695a2576896 /src | |
parent | 733adcf32c1cce288435940c66846a51ad29a464 (diff) |
Avoid illegal downcasts in texture and shader handling
Fixes bad type-cast during destruction when objects no longer has the
full type they used to.
Detected by UBSAN.
Change-Id: I4867091901d70d5a882656834eb97a704def1751
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/items/qquickopenglshadereffect.cpp | 7 | ||||
-rw-r--r-- | src/quick/items/qquickopenglshadereffect_p.h | 2 | ||||
-rw-r--r-- | src/quick/items/qquickopenglshadereffectnode.cpp | 8 | ||||
-rw-r--r-- | src/quick/items/qquickopenglshadereffectnode_p.h | 4 | ||||
-rw-r--r-- | src/quick/items/qquickshadereffect.cpp | 3 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgcontext.cpp | 2 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgcontext_p.h | 2 |
7 files changed, 14 insertions, 14 deletions
diff --git a/src/quick/items/qquickopenglshadereffect.cpp b/src/quick/items/qquickopenglshadereffect.cpp index 3aa00340b2..76cb3ace5c 100644 --- a/src/quick/items/qquickopenglshadereffect.cpp +++ b/src/quick/items/qquickopenglshadereffect.cpp @@ -221,7 +221,7 @@ QQuickOpenGLShaderEffectCommon::~QQuickOpenGLShaderEffectCommon() clearSignalMappers(shaderType); } -void QQuickOpenGLShaderEffectCommon::disconnectPropertySignals(QQuickItem *item, Key::ShaderType shaderType) +void QQuickOpenGLShaderEffectCommon::disconnectPropertySignals(QObject *obj, Key::ShaderType shaderType) { for (int i = 0; i < uniformData[shaderType].size(); ++i) { if (signalMappers[shaderType].at(i) == 0) @@ -229,12 +229,11 @@ void QQuickOpenGLShaderEffectCommon::disconnectPropertySignals(QQuickItem *item, const UniformData &d = uniformData[shaderType].at(i); auto mapper = signalMappers[shaderType].at(i); void *a = mapper; - QObjectPrivate::disconnect(item, mapper->signalIndex(), &a); + QObjectPrivate::disconnect(obj, mapper->signalIndex(), &a); if (d.specialType == UniformData::Sampler || d.specialType == UniformData::SamplerExternal) { QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value)); if (source) { - if (item->window()) - QQuickItemPrivate::get(source)->derefWindow(); + QQuickItemPrivate::get(source)->derefWindow(); QObject::disconnect(source, SIGNAL(destroyed(QObject*)), host, SLOT(sourceDestroyed(QObject*))); } } diff --git a/src/quick/items/qquickopenglshadereffect_p.h b/src/quick/items/qquickopenglshadereffect_p.h index 0c2adadc62..3087c1eb0b 100644 --- a/src/quick/items/qquickopenglshadereffect_p.h +++ b/src/quick/items/qquickopenglshadereffect_p.h @@ -89,7 +89,7 @@ struct Q_QUICK_PRIVATE_EXPORT QQuickOpenGLShaderEffectCommon ~QQuickOpenGLShaderEffectCommon(); - void disconnectPropertySignals(QQuickItem *item, Key::ShaderType shaderType); + void disconnectPropertySignals(QObject *item, Key::ShaderType shaderType); void connectPropertySignals(QQuickItem *item, const QMetaObject *itemMetaObject, Key::ShaderType shaderType); void updateParseLog(bool ignoreAttributes); void lookThroughShaderCode(QQuickItem *item, const QMetaObject *itemMetaObject, Key::ShaderType shaderType, const QByteArray &code); diff --git a/src/quick/items/qquickopenglshadereffectnode.cpp b/src/quick/items/qquickopenglshadereffectnode.cpp index f32b32491b..f96ebebcd6 100644 --- a/src/quick/items/qquickopenglshadereffectnode.cpp +++ b/src/quick/items/qquickopenglshadereffectnode.cpp @@ -477,11 +477,11 @@ void QQuickOpenGLShaderEffectMaterial::updateTextures() const } } -void QQuickOpenGLShaderEffectMaterial::invalidateTextureProvider(QSGTextureProvider *provider) +void QQuickOpenGLShaderEffectMaterial::invalidateTextureProvider(const QObject *provider) { for (int i = 0; i < textureProviders.size(); ++i) { if (provider == textureProviders.at(i)) - textureProviders[i] = 0; + textureProviders[i] = nullptr; } } @@ -505,10 +505,10 @@ void QQuickOpenGLShaderEffectNode::markDirtyTexture() Q_EMIT dirtyTexture(); } -void QQuickOpenGLShaderEffectNode::textureProviderDestroyed(QObject *object) +void QQuickOpenGLShaderEffectNode::textureProviderDestroyed(const QObject *object) { Q_ASSERT(material()); - static_cast<QQuickOpenGLShaderEffectMaterial *>(material())->invalidateTextureProvider(static_cast<QSGTextureProvider *>(object)); + static_cast<QQuickOpenGLShaderEffectMaterial *>(material())->invalidateTextureProvider(object); } void QQuickOpenGLShaderEffectNode::preprocess() diff --git a/src/quick/items/qquickopenglshadereffectnode_p.h b/src/quick/items/qquickopenglshadereffectnode_p.h index 7c75bb3126..6d68ba87b9 100644 --- a/src/quick/items/qquickopenglshadereffectnode_p.h +++ b/src/quick/items/qquickopenglshadereffectnode_p.h @@ -122,7 +122,7 @@ public: void setProgramSource(const QQuickOpenGLShaderEffectMaterialKey &source); void updateTextures() const; - void invalidateTextureProvider(QSGTextureProvider *provider); + void invalidateTextureProvider(const QObject *provider); static void cleanupMaterialCache(); @@ -159,7 +159,7 @@ Q_SIGNALS: private Q_SLOTS: void markDirtyTexture(); - void textureProviderDestroyed(QObject *object); + void textureProviderDestroyed(const QObject *object); }; QT_END_NAMESPACE diff --git a/src/quick/items/qquickshadereffect.cpp b/src/quick/items/qquickshadereffect.cpp index ab79b69c8c..05d9e5e36d 100644 --- a/src/quick/items/qquickshadereffect.cpp +++ b/src/quick/items/qquickshadereffect.cpp @@ -795,7 +795,8 @@ bool QQuickShaderEffect::event(QEvent *e) return QQuickItem::event(e); } #endif - m_impl->handleEvent(e); + if (m_impl) + m_impl->handleEvent(e); return QQuickItem::event(e); } diff --git a/src/quick/scenegraph/qsgcontext.cpp b/src/quick/scenegraph/qsgcontext.cpp index d9ed25c099..53648e352a 100644 --- a/src/quick/scenegraph/qsgcontext.cpp +++ b/src/quick/scenegraph/qsgcontext.cpp @@ -393,7 +393,7 @@ QSGTexture *QSGRenderContext::textureForFactory(QQuickTextureFactory *factory, Q void QSGRenderContext::textureFactoryDestroyed(QObject *o) { m_mutex.lock(); - m_texturesToDelete << m_textures.take(static_cast<QQuickTextureFactory *>(o)); + m_texturesToDelete << m_textures.take(o); m_mutex.unlock(); } diff --git a/src/quick/scenegraph/qsgcontext_p.h b/src/quick/scenegraph/qsgcontext_p.h index 6d70d7ef6b..282ce828af 100644 --- a/src/quick/scenegraph/qsgcontext_p.h +++ b/src/quick/scenegraph/qsgcontext_p.h @@ -194,7 +194,7 @@ protected: QPointer<QSGContext> m_sg; QMutex m_mutex; - QHash<QQuickTextureFactory *, QSGTexture *> m_textures; + QHash<QObject *, QSGTexture *> m_textures; QSet<QSGTexture *> m_texturesToDelete; QHash<QString, QSGDistanceFieldGlyphCache *> m_glyphCaches; |