From 10680f9bf7fc5dbfd39fa13cc4aa74e185ada2f3 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 23 Oct 2024 19:18:19 +0100 Subject: [PATCH] OpenGL: Detach OpenGL context after initialisation --- modules/juce_opengl/opengl/juce_OpenGLContext.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp index 8a4583f2b2..4d6a4fed2c 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp @@ -328,9 +328,11 @@ public: RenderStatus renderFrame (MessageManager::Lock& mmLock) { - if (! isFlagSet (state, StateFlags::initialised)) - { - switch (initialiseOnThread()) + ScopedContextActivator contextActivator; + + if (! isFlagSet (state, StateFlags::initialised)) + { + switch (initialiseOnThread (contextActivator)) { case InitResult::fatal: case InitResult::retry: return RenderStatus::noWork; @@ -346,7 +348,6 @@ public: #endif std::optional scopedLock; - ScopedContextActivator contextActivator; const auto stateToUse = state.fetch_and (StateFlags::persistent); @@ -617,14 +618,14 @@ public: } //============================================================================== - InitResult initialiseOnThread() + InitResult initialiseOnThread (ScopedContextActivator& activator) { // On android, this can get called twice, so drop any previous state. associatedObjectNames.clear(); associatedObjects.clear(); cachedImageFrameBuffer.release(); - context.makeActive(); + activator.activate (context); if (const auto nativeResult = nativeContext->initialiseOnRenderThread (context); nativeResult != InitResult::success) return nativeResult;