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.
IndexProgramming Questions & HelpSyntax Questions › my opengl memory crash
Page Index Toggle Pages: 1
my opengl memory crash (Read 1023 times)
my opengl memory crash
Jun 11th, 2009, 7:28pm
 
 import processing.opengl.*;
  
  PImage bug;
  void setup(){
   size(800,600,OPENGL);
   bug = createImage(width,height,RGB);
   bug.loadPixels();
  }
  
  
  void draw(){
   bug.pixels[0] = mouseX;
   bug.updatePixels();
   image(bug,0,0);
  }

I got image updatePixels on each frame, and memory usage also increase, is anything wrong with the code? Embarrassed

I build it with Processing 1.04
Re: my opengl memory crash
Reply #1 - Jun 12th, 2009, 8:42am
 
It looks like a result of the garbage collector and OpenGL.

When running, it builds up memory usage (caused by load- /updatePixels) and eventually drops back down.

The code itself seems fine.
I didn't see this build up in P2D, P3D, or JAVA2D.

How much ram does your computer have?
Do you have the 'increase max memory' option checked in preferences?
Re: my opengl memory crash
Reply #2 - Jun 13th, 2009, 11:36pm
 
My OS is WinXP,and 2G RAM.

If I run System.gc() every 2 frames, it will work fine and no more memory crash,
but this solution makes my application runs slowly.
Re: my opengl memory crash
Reply #3 - Jun 14th, 2009, 12:01am
 
Is your 'max memory' limit set high also?

Even with the limit set to 64MB, I still see memory usage climb up past 100MB before the gc kicks in automatically.
Re: my opengl memory crash
Reply #4 - Jun 14th, 2009, 4:28am
 
Quote:
If I run System.gc() every 2 frames, it will work fine and no more memory crash, but this solution makes my application runs slowly.


When you call System.gc() it does not immediately perform a garbage collection rather it creates an event which is placed on the main event (along with all the other GUI events) queue requesting a garbage collection. Also garbage collection is a CPU intensive operation so requesting it every 2 frames is bound to make your app unresponsive.

I suggest calling it every 2-3 seconds is probably enough.
Re: my opengl memory crash
Reply #5 - Jun 14th, 2009, 6:53am
 
NoahBuddy wrote on Jun 14th, 2009, 12:01am:
Is your 'max memory' limit set high also

Even with the limit set to 64MB, I still see memory usage climb up past 100MB before the gc kicks in automatically.


Yes, but it doesn't appear in P3D , P2D or Java2D mode. is there anything wrong with the OPEGN class itself
Re: my opengl memory crash
Reply #6 - Jun 14th, 2009, 4:11pm
 
Have you tried setting it lower?

Since it seems to overshoot the 'max limit', setting that limit close to your system memory could let it overshoot what you are capable of using.
Re: my opengl memory crash
Reply #7 - Jun 14th, 2009, 8:08pm
 
I got setting “increase maximum availabe memory" to 1400MB, but after running 5 - 10 minutes, the OutOfMemory Error thrown Embarrassed

An OutOfMemoryError means that your code is either using up too much memory
because of a bug (e.g. creating an array that's too large, or unintentionally
loading thousands of images), or that your sketch may need more memory to run.
If your sketch uses a lot of memory (for instance if it loads a lot of data files)
you can increase the memory available to your sketch using the Preferences window.
Exception in thread "Animation Thread" 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.copyIntBufferAsByteBuffer(BufferUtil.java:229)
     at javax.media.opengl.glu.GLU.copyToByteBuffer(GLU.java:1450)
     at javax.media.opengl.glu.GLU.gluBuild2DMipmapsJava(GLU.java:1524)
     at javax.media.opengl.glu.GLU.gluBuild2DMipmaps(GLU.java:1581)
     at processing.opengl.PGraphicsOpenGL$ImageCache.rebind(PGraphicsOpenGL.java:954)
     at processing.opengl.PGraphicsOpenGL.bindTexture(PGraphicsOpenGL.java:762)
     at processing.opengl.PGraphicsOpenGL.renderTriangles(PGraphicsOpenGL.java:684)
     at processing.core.PGraphics3D.endShape(PGraphics3D.java:626)
     at processing.core.PGraphics.endShape(PGraphics.java:1133)
     at processing.core.PGraphics.imageImpl(PGraphics.java:2261)
     at processing.core.PGraphics.image(PGraphics.java:2150)
     at processing.core.PApplet.image(PApplet.java:7087)
     at sketch_jun15a.draw(sketch_jun15a.java:30)
     at processing.core.PApplet.handleDraw(PApplet.java:1406)
     at processing.core.PApplet.run(PApplet.java:1311)
     at java.lang.Thread.run(Unknown Source)
Re: my opengl memory crash
Reply #8 - Jun 15th, 2009, 8:32am
 
Quote:
at sun.misc.Unsafe.allocateMemory(Native Method)

Since it is a native method, Java would not have direct control in limiting what it does.

Again, try setting “increase maximum availabe memory" to a low value. On both the computers (Windows 2K, XP) I have tested, it will still overshoot that limit, but the gc kicks in before exceeding the system memory.
Page Index Toggle Pages: 1