Skip to content

Commit 42f3456

Browse files
committed
dispose pixels array after init texture
1 parent 02e6cac commit 42f3456

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6646,9 +6646,16 @@ protected Object initCache(PImage img) {
66466646
if (tex == null || tex.contextIsOutdated()) {
66476647
tex = addTexture(img);
66486648
if (tex != null) {
6649+
boolean dispose = !img.loaded;
66496650
img.loadPixels();
66506651
tex.set(img.pixels, img.format);
66516652
img.setModified();
6653+
if (dispose) {
6654+
// We only used the pixels to load the image into the texture and the user did not request
6655+
// to load the pixels, so we should dispose the pixels array to avoid wasting memory
6656+
img.pixels = null;
6657+
img.loaded = false;
6658+
}
66526659
}
66536660
}
66546661
return tex;

0 commit comments

Comments
 (0)