From 9ba5dd5a309c10dbc391740d604a126ff1538d84 Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 21 Feb 2022 13:43:06 +0000 Subject: [PATCH] OpenGLDemo: Avoid races on Strings that are accessed from rendering thread and main thread --- examples/GUI/OpenGLDemo.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/GUI/OpenGLDemo.h b/examples/GUI/OpenGLDemo.h index a962d119ee..ad3e0bd560 100644 --- a/examples/GUI/OpenGLDemo.h +++ b/examples/GUI/OpenGLDemo.h @@ -906,6 +906,7 @@ public: void setShaderProgram (const String& vertexShader, const String& fragmentShader) { + const ScopedLock lock (shaderMutex); // Prevent concurrent access to shader strings and status newVertexShader = vertexShader; newFragmentShader = fragmentShader; } @@ -931,6 +932,7 @@ public: private: void handleAsyncUpdate() override { + const ScopedLock lock (shaderMutex); // Prevent concurrent access to shader strings and status controlsOverlay->statusLabel.setText (statusText, dontSendNotification); } @@ -1246,6 +1248,7 @@ private: OpenGLUtils::DemoTexture* textureToUse = nullptr; OpenGLUtils::DemoTexture* lastTexture = nullptr; + CriticalSection shaderMutex; String newVertexShader, newFragmentShader, statusText; struct BackgroundStar @@ -1258,6 +1261,8 @@ private: //============================================================================== void updateShader() { + const ScopedLock lock (shaderMutex); // Prevent concurrent access to shader strings and status + if (newVertexShader.isNotEmpty() || newFragmentShader.isNotEmpty()) { std::unique_ptr newShader (new OpenGLShaderProgram (openGLContext));