Loading...
Logo
Processing Forum

Weird OPENGL error

in Android Processing  •  2 years ago  
I have been trying to figure out the source of this error for a while... it only happens when I use A3D.

The console prints this:

Copy code
  1. FATAL EXCEPTION: GLThread 53
  2. java.lang.OutOfMemoryError: (Heap Size=30535KB, Allocated=18825KB, Bitmap Size=68KB)
  3. at processing.core.PTexture.createTexture(Unknown Source)
  4. at processing.core.PTexture.<init>(Unknown Source)
  5. at processing.core.PGraphicsAndroid3D.addTexture(Unknown Source)
  6. at processing.core.PGraphicsAndroid3D.getTexture(Unknown Source)
  7. at processing.core.PGraphicsAndroid3D.renderTriangles(Unknown Source)
  8. at processing.core.PGraphicsAndroid3D.endShape(Unknown Source)
  9. at processing.core.PGraphics.endShape(Unknown Source)
  10. at processing.core.PGraphics.imageImpl(Unknown Source)
  11. at processing.core.PGraphics.image(Unknown Source)
  12. at processing.core.PApplet.image(Unknown Source)
  13. at processing.android.test.b10806062011.B10806062011$Backdrop.update(B10806062011.java:182)
  14. at processing.android.test.b10806062011.B10806062011$Events.animate(B10806062011.java:357)
  15. at processing.android.test.b10806062011.B10806062011.draw(B10806062011.java:107)
  16. at processing.core.PApplet.handleDraw(Unknown Source)
  17. at processing.core.PGraphicsAndroid3D$A3DRenderer.onDrawFrame(Unknown Source)
  18. at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
  19. at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)


http://www.jaboston.com

Replies(19)

can you post the code that generates this error?
its when specify the renderer as A3D:


size(screenHeight, screenWidth, A3D);



or 


 public String sketchRenderer() {
    return A3D; 
  }








then when i switch it to A2D it works fine.
Ok, can you post more details about the sketch that generates the error? Does it happen with any sketch that uses A3D? Or only when you enable textures, etc?

A minimal sketch that reproduces the crash would be helpful.
Well after further testing and removing different bits of code... the error seems to appear nearly entirely randomly!

and I get different memory errors when I edit the code....

just got this memory error here:

FATAL EXCEPTION: GLThread 30
java.lang.OutOfMemoryError: (Heap Size=27463KB, Allocated=13923KB, Bitmap Size=58KB)
at processing.core.PTexture.createTexture(Unknown Source)
at processing.core.PTexture.<init>(Unknown Source)
at processing.core.PGraphicsAndroid3D.addTexture(Unknown Source)
at processing.core.PGraphicsAndroid3D.getTexture(Unknown Source)
at processing.core.PGraphicsAndroid3D.renderTriangles(Unknown Source)
at processing.core.PGraphicsAndroid3D.endShape(Unknown Source)
at processing.core.PGraphics.endShape(Unknown Source)
at processing.core.PGraphics.imageImpl(Unknown Source)
at processing.core.PGraphics.image(Unknown Source)
at processing.core.PApplet.image(Unknown Source)
at processing.android.test.b10806062011.B10806062011$Backdrop.update(B10806062011.java:192)
at processing.android.test.b10806062011.B10806062011$Events.animate(B10806062011.java:377)
at processing.android.test.b10806062011.B10806062011.draw(B10806062011.java:118)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphicsAndroid3D$A3DRenderer.onDrawFrame(Unknown Source)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)


Hope that helps.... :S
Looks like your app is running out of texture memory, and somehow the audio files have an effect on this. Yes, very weird...

The only thing I can imagine at the moment is that you are loading lots of images and audio files, and/or the resolution/bitrate of some of them is very high. 

I don't know the specs of the hardware you are using, but if the video memory is shared with the main memory, and the total amount is not too large, maybe that's the reason for the crash... 

What device are you using? Also, what version of Android?


a Desire S with Gingerbread

http://www.jaboston.com
Ok, that's a fairly recent phone with a good amount of memory... 

Are you re-using your image objects during the execution of the app, something like this:

Copy code
  1. void setup() {
  2.   ...
  3.   img = loadImage("img1.jpg");
  4. }

  5. void draw() {
  6.   ...
  7.   if (reload) {
  8.     img = loadImage("img2.jpg");
  9.   }
  10. }

Anyways, it is difficult to find the reason for the crash without looking at any code.

here is my setup function

Copy code
  1. void setup()
  2. {
  3.   orientation(LANDSCAPE);
  4.   font = loadFont("Agency.vlw"); 
  5.   blob = loadImage("blob.png");
  6.   greenEn1 = loadImage("greenEn1.png");
  7.   greenEn2 = loadImage("greenEn2.png");
  8.   blueEn1 = loadImage("blueEn1.png");  
  9.   yellowEn1 = loadImage("yellowEn1.png");
  10.   yellowEn2 = loadImage("yellowEn2.png");
  11.   blueEn = loadImage("blueEn1.png");
  12.   back1 = loadImage("elebacklights.png"); // image is 1600 x 600
  13.   back2 = loadImage("elebacklights2.png");
  14.   back3 = loadImage("eleback3.png"); 
  15.   chatlog = loadImage("chatlog.png");
  16.   font = loadFont("Agency.vlw");  
  17.   water = loadImage("waterdrop.png");
  18.   poison = loadImage("poison.png");
  19.   fire = loadImage("flame.png");
  20.   badf1 = loadImage("badface1.gif");
  21.   badf2 = loadImage("badface2.gif");
  22.   buttons = loadImage("buttons.png");
  23.   accel = new AccelerometerManager(this);
  24.   longCooldown = false;
  25.   //    ps = new ParticleSystem(1, new PVector(width/2,height/2,0));
  26.   //    redspell = new ParticleSystem(1, new PVector(width/2,height/2,0));
  27.   //    greenspell = new ParticleSystem(1, new PVector(width/2,height/2,0));
  28.   posX = 0; 
  29.   posY = 0; 
  30.   centerX = 0; 
  31.   centerY = 0;
  32.   counter = 0; 
  33.   re1 = 0; 
  34.   re2 = 0; 
  35.   re3 = 0;
  36.   soundEffects.settings();
  37.   backdrop.settings();
  38.   events.settings();
  39.   soundsInit();
  40.   endGame = false;
  41.   audiorunonce = true;
  42.   mainMenu = true;
  43.   noStroke();
  44. }
here is a class where I am using the images I loaded:

Copy code
  1. class Backdrop {
  2.   int scrollback1, scrollback2, scrollback3;
  3.   Backdrop() {
  4.   }  

  5.   void settings() {
  6.   }


  7.   void update() {

  8. //   being called in main draw() method
  9. pushStyle();
  10. scrollback2 = frameCount%1600;
  11. image(back2, -scrollback2/2, 0);
  12. popStyle();
  13. // stepi is used for stepping through a 'timeline' type sequence of events to show a story. or load different enemies etc.
  14.     if (stepi == 0) {  backdrop.chatlog();  }
  15.   
  16.                   }

  17.   void chatlog() {
  18.     image(chatlog, 210, screenHeight-105);
  19.   }
  20. }

I have about 16 different classes making it a really complex situation...

I guess the deeper u go into the rabbit hole the harder it is to get out 

skype: tsugaruddr

I will start by putting together a simple sketch that just loads a similar number of images as in your case, including a few high-res ones, and and draws them continuously, to see if I can get the out-of-memory error.
thankyou!

I have gone through the code tons of times looking for any loadImage sequences that may be being repeated or looped.
I am quite stuck on what could be causing it now...

ok, I'm running the following stress-test sketch:

Copy code
  1. int num = 20;
  2. PImage images[];

  3. void setup() {
  4.   size(screenWidth, screenHeight, A3D);
  5.   orientation(LANDSCAPE);
  6.   
  7.   images = new PImage[num];
  8.   for (int i = 0; i < images.length; i++) {
  9.     images[i] = loadImage("img" + i + ".jpg");
  10.   }
  11. }

  12. void draw() {
  13.   background(0);
  14.   for (int i = 0; i < images.length; i++) {
  15.     float x = random(0, width);
  16.     float y = random(0, height);
  17.     pushStyle();
  18.     image(images[i], x, y, width - x, height - y);
  19.     popStyle();
  20.   }      
  21. }

  22. void mousePressed() {
  23.   for (int i = 0; i < images.length; i++) {
  24.     images[i].delete();
  25.     images[i] = loadImage("img" + i + ".jpg");
  26.   }
  27. }
Can you try on your phone using your set of images?
sure I will do that now!

This is the game running on my galaxy tab (and it doesnt get the error on that!).... 


I don't know if that helps make the problem clearer. thanks!

yup it crashed with the error:

Copy code
  1. FATAL EXCEPTION: GLThread 10
  2. java.lang.OutOfMemoryError: (Heap Size=29831KB, Allocated=18813KB, Bitmap Size=24KB)
  3. at processing.core.PTexture.createTexture(Unknown Source)
  4. at processing.core.PTexture.<init>(Unknown Source)
  5. at processing.core.PGraphicsAndroid3D.addTexture(Unknown Source)
  6. at processing.core.PGraphicsAndroid3D.getTexture(Unknown Source)
  7. at processing.core.PGraphicsAndroid3D.renderTriangles(Unknown Source)
  8. at processing.core.PGraphicsAndroid3D.endShape(Unknown Source)
  9. at processing.core.PGraphics.endShape(Unknown Source)
  10. at processing.core.PGraphics.imageImpl(Unknown Source)
  11. at processing.core.PGraphics.image(Unknown Source)
  12. at processing.core.PGraphics.image(Unknown Source)
  13. at processing.core.PApplet.image(Unknown Source)
  14. at processing.android.test.pimagetest.PImagetest.draw(PImagetest.java:33)
  15. at processing.core.PApplet.handleDraw(Unknown Source)
  16. at processing.core.PGraphicsAndroid3D$A3DRenderer.onDrawFrame(Unknown Source)
  17. at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
  18. at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
AND.... to make the evidence more solid... this ran with no problem on my galaxy tab!!!
So although the desire S has better specs than the galaxy tab... the galaxy tab doesnt have memory errors... 
So my desire S cant handle the image load.... what do I do now :o!? (bring it back to the shop? get a less recent phone :D?).

http://www.jaboston.com
Can you list the resolutions of all the images you load in your app? Thanks!
50x50 gif
50x50 gif
400x709 png
170x88 png
170x88 png
100x600 png
800x110 png
1600x600 png (only loading one of these 1600x600 pngs at the moment... but I will load more.... they are used for the background).
1600x600 png
1600x600 png
1600x600 png
1600x600 png
85x82 png
85x82 png
85x82 png
85x82 png
85x82 png
85x82 png
85x82 png
85x82 png
60x60 png
100x100 png
100x100 png
150x100 png
150x142 png
60x60 png
120x54 png
120x54 png

I also just found that if I resize an image for the background:

  back3 = loadImage("eleback3.png"); 
  back3.resize(back3.width*4, back3.height*4);

it then will crash out with the same memory error (on the galaxy tab).

eleback3.png in this case is 51.6KB and the dimensions are 400x300. I also tried the same method with a gif of the same dimensions.

both errors with: 

FATAL EXCEPTION: GLThread 9
java.lang.OutOfMemoryError
at processing.core.PTexture.createTexture(Unknown Source)
at processing.core.PTexture.<init>(Unknown Source)
....
Maybe I found a solution for this out-of-memory issue. But you would need to compile Processing from the trunk in order to try it out ( rev8019).
ok! released the game to the android market to see what errors people would get.... the same one pops up (only that)...

havent tried your revision yet.... but going to try now....  Do you want me to send my source code to you for you to test?

(does your 0198 bag of awesome fix it ;D?)

v1.2.4
Jun 21, 2011 3:08:44 AM
1 reports/week
1 reports

java.lang.OutOfMemoryError
at processing.core.PTexture.createTexture(Unknown Source)
at processing.core.PTexture.<init>(Unknown Source)
at processing.core.PFontTexture.addTexture(Unknown Source)
at processing.core.PFontTexture.initTexture(Unknown Source)
at processing.core.PFontTexture.<init>(Unknown Source)
at processing.core.PGraphicsAndroid3D.textLineImpl(Unknown Source)
at processing.core.PGraphics.textLineAlignImpl(Unknown Source)
at processing.core.PGraphics.text(Unknown Source)
at processing.core.PApplet.text(Unknown Source)
at processing.android.test.e1.E1$Startup.start(E1.java:2469)
at processing.android.test.e1.E1$Events.animate(E1.java:951)
at processing.android.test.e1.E1.draw(E1.java:302)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphicsAndroid3D$A3DRenderer.onDrawFrame(Unknown Source)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1341)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)

v1.0
Jun 20, 2011 4:18:51 AM
2 reports/week
3 reports

java.lang.OutOfMemoryError
at processing.core.PTexture.createTexture(Unknown Source)
at processing.core.PTexture.<init>(Unknown Source)
at processing.core.PFontTexture.addTexture(Unknown Source)
at processing.core.PFontTexture.initTexture(Unknown Source)
at processing.core.PFontTexture.<init>(Unknown Source)
at processing.core.PGraphicsAndroid3D.textLineImpl(Unknown Source)
at processing.core.PGraphics.textLineAlignImpl(Unknown Source)
at processing.core.PGraphics.text(Unknown Source)
at processing.core.PApplet.text(Unknown Source)
at processing.android.test.e1.E1$Startup.start(E1.java:2527)
at processing.android.test.e1.E1$Events.animate(E1.java:858)
at processing.android.test.e1.E1.draw(E1.java:273)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphicsAndroid3D$A3DRenderer.onDrawFrame(Unknown Source)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1341)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)

v1.0
Jun 18, 2011 12:21:59 AM
0 reports/week
4 reports

java.lang.OutOfMemoryError
at processing.core.PTexture.createTexture(Unknown Source)
at processing.core.PTexture.<init>(Unknown Source)
at processing.core.PFontTexture.addTexture(Unknown Source)
at processing.core.PFontTexture.initTexture(Unknown Source)
at processing.core.PFontTexture.<init>(Unknown Source)
at processing.core.PGraphicsAndroid3D.textLineImpl(Unknown Source)
at processing.core.PGraphics.textLineAlignImpl(Unknown Source)
at processing.core.PGraphics.text(Unknown Source)
at processing.core.PApplet.text(Unknown Source)
at processing.android.test.e1.E1$Startup.start(E1.java:2527)
at processing.android.test.e1.E1$Events.animate(E1.java:858)
at processing.android.test.e1.E1.draw(E1.java:273)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphicsAndroid3D$A3DRenderer.onDrawFrame(Unknown Source)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1332)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)

http://www.jaboston.com
0198 does include the fix I mentioned earlier.
Ok cheers andres :D. as always I bow to your fixes of godliness ;).

Ill post here if the out of memory error is persisting or not :). 

many thanks :).

http://www.jaboston.com