Browse Source

Fixed a potential data race in OpenGLContext::CachedImage

tags/2021-05-28
ed 5 years ago
parent
commit
b2d8f45e14
1 changed files with 6 additions and 5 deletions
  1. +6
    -5
      modules/juce_opengl/opengl/juce_OpenGLContext.cpp

+ 6
- 5
modules/juce_opengl/opengl/juce_OpenGLContext.cpp View File

@@ -105,7 +105,7 @@ public:
if (renderThread != nullptr) if (renderThread != nullptr)
{ {
// make sure everything has finished executing // make sure everything has finished executing
destroying.set (1);
destroying = true;
if (workQueue.size() > 0) if (workQueue.size() > 0)
{ {
@@ -224,7 +224,9 @@ public:
bool renderFrame() bool renderFrame()
{ {
MessageManager::Lock::ScopedTryLockType mmLock (messageManagerLock, false); MessageManager::Lock::ScopedTryLockType mmLock (messageManagerLock, false);
const bool isUpdating = needsUpdate.compareAndSetBool (0, 1);
auto isUpdatingTestValue = true;
auto isUpdating = needsUpdate.compare_exchange_strong (isUpdatingTestValue, false);
if (context.renderComponents && isUpdating) if (context.renderComponents && isUpdating)
{ {
@@ -613,7 +615,7 @@ public:
void execute (OpenGLContext::AsyncWorker::Ptr workerToUse, bool shouldBlock, bool calledFromDestructor = false) void execute (OpenGLContext::AsyncWorker::Ptr workerToUse, bool shouldBlock, bool calledFromDestructor = false)
{ {
if (calledFromDestructor || destroying.get() == 0)
if (calledFromDestructor || ! destroying)
{ {
if (shouldBlock) if (shouldBlock)
{ {
@@ -671,8 +673,7 @@ public:
#else #else
bool shadersAvailable = false; bool shadersAvailable = false;
#endif #endif
bool hasInitialised = false;
Atomic<int> needsUpdate { 1 }, destroying;
std::atomic<bool> hasInitialised { false }, needsUpdate { true }, destroying { false };
uint32 lastMMLockReleaseTime = 0; uint32 lastMMLockReleaseTime = 0;
#if JUCE_MAC #if JUCE_MAC


Loading…
Cancel
Save