From 440589a0747d9668fec3ff924b390d75be5c6733 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Thu, 5 Jan 2017 19:01:36 +0000 Subject: Fix race condition with dynamic texture updates Mutex protect the dirty flag written by both the threadpool and the submisison thread. Without this it is easy to end up with no textures being used when the user updates them under certain workloads. Task-number: QTBUG-57939 Change-Id: Idba4137f023ccfcb6ceb409cc6df3a2b4dddf510 Reviewed-by: Paul Lemire Reviewed-by: Kevin Ottens --- src/render/texture/gltexture.cpp | 4 ++++ src/render/texture/gltexture_p.h | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/render/texture/gltexture.cpp b/src/render/texture/gltexture.cpp index 1a76617a7..0e3291fb0 100644 --- a/src/render/texture/gltexture.cpp +++ b/src/render/texture/gltexture.cpp @@ -97,6 +97,7 @@ void GLTexture::destroyGLTexture() { delete m_gl; m_gl = nullptr; + QMutexLocker locker(&m_dirtyFlagMutex); m_dirty = 0; destroyResources(); @@ -104,6 +105,7 @@ void GLTexture::destroyGLTexture() QOpenGLTexture* GLTexture::getOrCreateGLTexture() { + QMutexLocker locker(&m_dirtyFlagMutex); bool needUpload = false; bool texturedDataInvalid = false; @@ -210,6 +212,7 @@ void GLTexture::setParameters(const TextureParameters ¶ms) { if (m_parameters != params) { m_parameters = params; + QMutexLocker locker(&m_dirtyFlagMutex); m_dirty |= Parameters; } } @@ -218,6 +221,7 @@ void GLTexture::setProperties(const TextureProperties &props) { if (m_properties != props) { m_properties = props; + QMutexLocker locker(&m_dirtyFlagMutex); m_dirty |= Properties; } } diff --git a/src/render/texture/gltexture_p.h b/src/render/texture/gltexture_p.h index 7c6bf9c90..424e77854 100644 --- a/src/render/texture/gltexture_p.h +++ b/src/render/texture/gltexture_p.h @@ -142,7 +142,11 @@ public: // Called by TextureDataManager when it has new texture data from // a generator that needs to be uploaded. - void requestUpload() { m_dirty |= TextureData; } + void requestUpload() + { + QMutexLocker locker(&m_dirtyFlagMutex); + m_dirty |= TextureData; + } protected: @@ -178,6 +182,7 @@ private: bool m_unique; DirtyFlags m_dirty; + QMutex m_dirtyFlagMutex; QOpenGLTexture *m_gl; TextureDataManager *m_textureDataManager; -- cgit v1.2.1