1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

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

This commit is contained in:
reuk 2022-02-21 13:43:06 +00:00
parent 9bd52d59af
commit 9ba5dd5a30
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

View file

@ -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<OpenGLShaderProgram> newShader (new OpenGLShaderProgram (openGLContext));