mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Merge pull request #3874 from JakubValtar/opengl-cache-dependencies
Remove circular dependence
This commit is contained in:
@@ -703,13 +703,24 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
|
||||
@Override
|
||||
public void setCache(PImage image, Object storage) {
|
||||
if (image instanceof PGraphicsOpenGL) {
|
||||
// Prevent strong reference to the key from the value by wrapping
|
||||
// the Texture into WeakReference (proposed solution by WeakHashMap docs)
|
||||
getPrimaryPG().cacheMap.put(image, new WeakReference<>(storage));
|
||||
return;
|
||||
}
|
||||
getPrimaryPG().cacheMap.put(image, storage);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getCache(PImage image) {
|
||||
return getPrimaryPG().cacheMap.get(image);
|
||||
Object storage = getPrimaryPG().cacheMap.get(image);
|
||||
if (storage != null && storage.getClass() == WeakReference.class) {
|
||||
// Unwrap the value, use getClass() for fast check
|
||||
return ((WeakReference) storage).get();
|
||||
}
|
||||
return storage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user