From cb34975457c3c3d5ceec7cf00ff9c52ded6c8c9b Mon Sep 17 00:00:00 2001 From: attila Date: Wed, 22 Oct 2025 17:00:48 +0200 Subject: [PATCH] Fix crash after OpenGL::detach in the presence of buffered child components The crash fixed by this commit could be triggered by attaching an OpenGL context to a component, calling setBufferedToImage (true) on one of its child components, and then detaching the OpenGL context from the parent. Since 4ba01a80a0b25a258d3236887ab690a292a7d055 we are creating images with the current rendering context's native image type, so the above scenario would leave an image buffer that references the detached context. --- modules/juce_opengl/opengl/juce_OpenGLContext.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp index 27f8ace149..b7ad307f7a 100644 --- a/modules/juce_opengl/opengl/juce_OpenGLContext.cpp +++ b/modules/juce_opengl/opengl/juce_OpenGLContext.cpp @@ -1102,11 +1102,19 @@ public: detach(); } + static void clearCachedImagesInComponentTree (Component& root) + { + root.setCachedComponentImage (nullptr); + + for (auto* child : root.getChildren()) + clearCachedImagesInComponentTree (*child); + } + void detach() { auto& comp = *getComponent(); stop(); - comp.setCachedComponentImage (nullptr); + clearCachedImagesInComponentTree (comp); context.nativeContext = nullptr; }