Guard with a mutex in QOpenGLProgramBinaryCache where needed
While there is likely no example of it in Qt itself, applications can use QOpenGLShaderProgram instances on different threads. These instances have nothing to do with each other but they do share a global cache object. This becomes problematic without proper synchronization. Change-Id: I80faf73f34af7e67349eee916bb3f216e22c07fd Fixes: QTBUG-77469 Reviewed-by: Christian Strømme <christian.stromme@qt.io>
This commit is contained in:
parent
6d3a454693
commit
257bd49c1f
@ -263,6 +263,7 @@ public:
|
||||
|
||||
bool QOpenGLProgramBinaryCache::load(const QByteArray &cacheKey, uint programId)
|
||||
{
|
||||
QMutexLocker lock(&m_mutex);
|
||||
if (m_memCache.contains(cacheKey)) {
|
||||
const MemCacheEntry *e = m_memCache[cacheKey];
|
||||
return setProgramBinary(programId, e->format, e->blob.constData(), e->blob.size());
|
||||
@ -401,6 +402,7 @@ void QOpenGLProgramBinaryCache::save(const QByteArray &cacheKey, uint programId)
|
||||
GLint outSize = 0;
|
||||
#if defined(QT_OPENGL_ES_2)
|
||||
if (context->isOpenGLES() && context->format().majorVersion() < 3) {
|
||||
QMutexLocker lock(&m_mutex);
|
||||
initializeProgramBinaryOES(context);
|
||||
getProgramBinaryOES(programId, blobSize, &outSize, &blobFormat, p);
|
||||
} else
|
||||
|
@ -54,6 +54,7 @@
|
||||
#include <QtGui/qtguiglobal.h>
|
||||
#include <QtGui/qopenglshaderprogram.h>
|
||||
#include <QtCore/qcache.h>
|
||||
#include <QtCore/qmutex.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -99,6 +100,7 @@ private:
|
||||
void initializeProgramBinaryOES(QOpenGLContext *context);
|
||||
bool m_programBinaryOESInitialized = false;
|
||||
#endif
|
||||
QMutex m_mutex;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
Reference in New Issue
Block a user