1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-05 03:50:07 +00:00

Component: Recreate cached images if ideal type changes

This is intended to fix an issue where drawing a component snapshot into
a temporary OpenGL image can fail, because the GL context may not be
bound.
This commit is contained in:
reuk 2025-05-14 18:29:38 +01:00
parent 86732069c7
commit bf54fb1fe9
No known key found for this signature in database

View file

@ -214,14 +214,20 @@ public:
auto scale = g.getInternalContext().getPhysicalPixelScaleFactor();
auto scaledBounds = c.getLocalBounds() * scale;
if (effectImage.getBounds() != scaledBounds)
const auto preferredType = g.getInternalContext().getPreferredImageTypeForTemporaryImages();
const auto pixelData = effectImage.getPixelData();
const auto shouldCreateImage = pixelData == nullptr
|| pixelData->width != scaledBounds.getWidth()
|| pixelData->height != scaledBounds.getHeight()
|| pixelData->createType()->getTypeID() != preferredType->getTypeID();
if (shouldCreateImage)
{
auto tempImageType = g.getInternalContext().getPreferredImageTypeForTemporaryImages();
effectImage = Image { c.isOpaque() ? Image::RGB : Image::ARGB,
scaledBounds.getWidth(),
scaledBounds.getHeight(),
false,
*tempImageType };
*preferredType };
effectImage.setBackupEnabled (false);
}