I don't know if this is a Processing bug, or OpenGL problem, or video card problem, or just plain old operator error, but I'm getting an out of memory error runtime exception when using textures with OpenGL. Any help would be appreciated...
Specifically what I'm doing is grabbing the entire frame's pixels at the end of each draw with get() in order to use that image as the texture for the next frame. (recursive feedback, pretty cool, was inspired to try it in Processing by Paul Prudence's vvvv work: http://www.flickr.com/photos/transphormetic/sets/72157600095395068/)
Here's minimal sample code that can duplicate the problem (0124 Beta on WinXP):
Quote:
import processing.opengl.*;
PImage tex;
void setup() {
size(256,256,OPENGL);
textureMode(NORMALIZED);
tex = createImage(256,256,ARGB);
stroke(255);
}
void draw() {
println("frameCount = " + frameCount);
background(0);
translate(width/2f, height/2f);
beginShape(QUADS);
texture(tex);
vertex(-50,-50, 0,0);
vertex(50,-50, 1,0);
vertex(50,50, 1,1);
vertex(-50,50, 0,1);
endShape();
tex = get();
}
It'll work for some number of frames before blowing up, does that suggest perhaps a memory leak? (maybe in the OpenGL version of get()??) On my PC with that sketch and the VM set to 1024M, it's about 2268 frames (and not surprisingly it takes fewer frames til blowup as resolution increases). Here's the error:
Code:
java.lang.RuntimeException: java.lang.OutOfMemoryError
at processing.opengl.PGraphicsOpenGL.requestDisplay(PGraphicsOpenGL.java:172)
at processing.core.PApplet.run(PApplet.java:1450)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.OutOfMemoryError
at sun.misc.Unsafe.allocateMemory(Native Method)
at java.nio.DirectByteBuffer.<init>(Unknown Source)
at java.nio.ByteBuffer.allocateDirect(Unknown Source)
at com.sun.opengl.util.BufferUtil.newByteBuffer(BufferUtil.java:65)
at com.sun.opengl.util.BufferUtil.newIntBuffer(BufferUtil.java:90)
at processing.opengl.PGraphicsOpenGL$ImageCache.rebind(PGraphicsOpenGL.java:875)
at processing.opengl.PGraphicsOpenGL.bindTexture(PGraphicsOpenGL.java:714)
at processing.opengl.PGraphicsOpenGL.render_triangles(PGraphicsOpenGL.java:523)
at processing.core.PGraphics3D.endShape(PGraphics3D.java:994)
at processing.core.PGraphics.endShape(PGraphics.java:1115)
at processing.core.PApplet.endShape(PApplet.java:7049)
at Temporary_770_451.draw(Temporary_770_451.java:35)
at processing.core.PApplet.handleDisplay(PApplet.java:1355)
at processing.opengl.PGraphicsOpenGL$1.display(PGraphicsOpenGL.java:221)
at com.sun.opengl.impl.GLDrawableHelper.display(GLDrawableHelper.java:78)
at javax.media.opengl.GLCanvas$DisplayAction.run(GLCanvas.java:281)
at com.sun.opengl.impl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:194)
at javax.media.opengl.GLCanvas$DisplayOnEventDispatchThreadAction.run(GLCanvas.java:298)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Is there something I should be doing to explicitly release memory or bound textures from prior frames?