We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexSuggestions & BugsSoftware Bugs › OpenGL OutOfMemoryError exception
Page Index Toggle Pages: 1
OpenGL OutOfMemoryError exception (Read 2692 times)
OpenGL OutOfMemoryError exception
May 24th, 2007, 1:50am
 
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?
Re: OpenGL OutOfMemoryError exception
Reply #1 - May 24th, 2007, 5:20pm
 
FYI, problem also appears to occur with P3D, though it takes about twice as many frames, and all that's reported is "java.lang.OutOfMemoryError".
Re: OpenGL OutOfMemoryError exception
Reply #2 - May 24th, 2007, 6:51pm
 
Try adding tex=null; just before tex=get(); just to make sure the GC knows that whatever it was previously is now free to be disposed of.
Re: OpenGL OutOfMemoryError exception
Reply #3 - May 24th, 2007, 8:59pm
 
Thanks John, unfortunately no effect.  I even tried following it immediately with an explicit hint via System.gc(); but problem remains.  Sad
Re: OpenGL OutOfMemoryError exception
Reply #4 - May 26th, 2007, 12:27am
 
It could be it's just not collecting fast enough? Did you try upping the max memory in preferences?
Re: OpenGL OutOfMemoryError exception
Reply #5 - May 26th, 2007, 5:19pm
 
ddf wrote on May 26th, 2007, 12:27am:
Did you try upping the max memory in preferences


Thanks, yep, but didn't help.  But after some more careful record-keeping, I've found something VERY interesting...

Upping the Java VM memory via the preferences panel actually DECREASES the number of frames until crashing. (and vice versa) So it's not running out of VM memory, it's running out of system memory.  (the more you allocate to the JVM, the less left to the system, so the sooner the crash) (can also verify this by launching other apps in background and noting effect on crash rate)

So it's gotta be from some Java DLL that's doing system allocates and then not freeing them, right, because as far as I can tell I'm releasing all references to variables that *I* control in JVM.  I would suspect OpenGL except that it also happens with P3D.

I'm using the provided JRE, perhaps I should experiment with others and see if I can isolate it to the JRE.  Any ideas, anyone  thx

[Edit:] confirmation:  dumping out runtine.total/free/maxMemory() shows JVM has hardly any memory usage, while Task Manager shows java.exe growing and growing until crash.
Re: OpenGL OutOfMemoryError exception
Reply #6 - Jun 24th, 2007, 7:20pm
 
this should be bug #150, which has been fixed for 0125.
Page Index Toggle Pages: 1