Browse Source

OpenGLDemo: Avoid races on Strings that are accessed from rendering thread and main thread

v6.1.6
reuk 3 years ago
parent
commit
9ba5dd5a30
No known key found for this signature in database GPG Key ID: 9ADCD339CFC98A11
1 changed files with 5 additions and 0 deletions
  1. +5
    -0
      examples/GUI/OpenGLDemo.h

+ 5
- 0
examples/GUI/OpenGLDemo.h View File

@@ -906,6 +906,7 @@ public:
void setShaderProgram (const String& vertexShader, const String& fragmentShader) void setShaderProgram (const String& vertexShader, const String& fragmentShader)
{ {
const ScopedLock lock (shaderMutex); // Prevent concurrent access to shader strings and status
newVertexShader = vertexShader; newVertexShader = vertexShader;
newFragmentShader = fragmentShader; newFragmentShader = fragmentShader;
} }
@@ -931,6 +932,7 @@ public:
private: private:
void handleAsyncUpdate() override void handleAsyncUpdate() override
{ {
const ScopedLock lock (shaderMutex); // Prevent concurrent access to shader strings and status
controlsOverlay->statusLabel.setText (statusText, dontSendNotification); controlsOverlay->statusLabel.setText (statusText, dontSendNotification);
} }
@@ -1246,6 +1248,7 @@ private:
OpenGLUtils::DemoTexture* textureToUse = nullptr; OpenGLUtils::DemoTexture* textureToUse = nullptr;
OpenGLUtils::DemoTexture* lastTexture = nullptr; OpenGLUtils::DemoTexture* lastTexture = nullptr;
CriticalSection shaderMutex;
String newVertexShader, newFragmentShader, statusText; String newVertexShader, newFragmentShader, statusText;
struct BackgroundStar struct BackgroundStar
@@ -1258,6 +1261,8 @@ private:
//============================================================================== //==============================================================================
void updateShader() void updateShader()
{ {
const ScopedLock lock (shaderMutex); // Prevent concurrent access to shader strings and status
if (newVertexShader.isNotEmpty() || newFragmentShader.isNotEmpty()) if (newVertexShader.isNotEmpty() || newFragmentShader.isNotEmpty())
{ {
std::unique_ptr<OpenGLShaderProgram> newShader (new OpenGLShaderProgram (openGLContext)); std::unique_ptr<OpenGLShaderProgram> newShader (new OpenGLShaderProgram (openGLContext));


Loading…
Cancel
Save