diff options
author | Juan José Casafranca <juan.casafranca@kdab.com> | 2017-04-24 12:32:45 +0200 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2017-04-25 09:41:41 +0000 |
commit | 21d891722cbaa18f6352804d5b4a3d4cf6911c41 (patch) | |
tree | c277dc50674e3d0ac30f0308bb81af1597840df0 | |
parent | df4b063c5b988a63d871d4ac101c77a928791f43 (diff) |
Verify a texture is valid before update
Texture images may be deleted before the texture it references to them.
This happens when the texture is added and removed very fast.
Verify all the texture images that the texture reference still exist
before updating the texture.
Task-number: QTBUG-59418
Change-Id: Idacbdd1a45eb0fa5b871d57688e9d02b823f7b5f
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r-- | src/render/backend/renderer.cpp | 5 | ||||
-rw-r--r-- | src/render/texture/texture.cpp | 10 | ||||
-rw-r--r-- | src/render/texture/texture_p.h | 1 |
3 files changed, 16 insertions, 0 deletions
diff --git a/src/render/backend/renderer.cpp b/src/render/backend/renderer.cpp index 0fda6e5b4..42909d8be 100644 --- a/src/render/backend/renderer.cpp +++ b/src/render/backend/renderer.cpp @@ -1061,6 +1061,11 @@ void Renderer::updateGLResources() // Render Thread void Renderer::updateTexture(Texture *texture) { + // Check that the current texture images are still in place, if not, do not update + const bool isValid = texture->isValid(); + if (!isValid) + return; + // For implementing unique, non-shared, non-cached textures. // for now, every texture is shared by default diff --git a/src/render/texture/texture.cpp b/src/render/texture/texture.cpp index 8dd9ad229..13991ec4a 100644 --- a/src/render/texture/texture.cpp +++ b/src/render/texture/texture.cpp @@ -246,6 +246,16 @@ void Texture::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) BackendNode::sceneChangeEvent(e); } +bool Texture::isValid() const +{ + for (const auto handle : m_textureImages) { + TextureImage *img = m_textureImageManager->data(handle); + if (img == nullptr) + return false; + } + return true; +} + void Texture::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) { const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QAbstractTextureData>>(change); diff --git a/src/render/texture/texture_p.h b/src/render/texture/texture_p.h index f99d1d38b..4fe4e2c7c 100644 --- a/src/render/texture/texture_p.h +++ b/src/render/texture/texture_p.h @@ -157,6 +157,7 @@ public: inline const QVector<HTextureImage>& textureImages() const { return m_textureImages; } inline const QTextureGeneratorPtr& dataGenerator() const { return m_dataFunctor; } + bool isValid() const; private: void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL; |