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

Component: Add function to clear all cached image resources

In the DemoRunner, switching to and fro between the Settings tab and
the Demo tab displaying the OpenGL demo could lead to
GL_INVALID_OPERATION errors. This is because closing the demo shuts
down the GL context, destroying resources such as framebuffers. If any
Image objects backed by framebuffers outlive the context, they will be
invalidated. Component effect images are especially likely to hold onto
invalid framebuffer references.

With this change in place, images cached by Components will be
invalidated when the attached GL context goes out of scope, and will be
recreated when the new context is created.
This commit is contained in:
reuk 2025-05-15 19:18:54 +01:00
parent bf54fb1fe9
commit 84eed04a59
No known key found for this signature in database
3 changed files with 18 additions and 2 deletions

View file

@ -247,6 +247,11 @@ public:
effect->applyEffect (effectImage, g, scale, ignoreAlphaLevel ? 1.0f : c.getAlpha());
}
void releaseResources()
{
effectImage = {};
}
private:
Image effectImage;
ImageEffectFilter* effect;
@ -613,6 +618,15 @@ void Component::setBufferedToImage (bool shouldBeBuffered)
}
}
void Component::invalidateCachedImageResources()
{
if (cachedImage != nullptr)
cachedImage->releaseResources();
if (effectState != nullptr)
effectState->releaseResources();
}
//==============================================================================
void Component::reorderChildInternal (int sourceIndex, int destIndex)
{

View file

@ -2504,6 +2504,9 @@ public:
*/
CachedComponentImage* getCachedComponentImage() const noexcept { return cachedImage.get(); }
/** Invalidates cached images, both in the CachedComponentImage (if any) and the image effect state. */
void invalidateCachedImageResources();
/** Sets a flag to indicate whether mouse drag events on this Component should be ignored when it is inside a
Viewport with drag-to-scroll functionality enabled. This is useful for Components such as sliders that
should not move when their parent Viewport when dragged.