Author Topic: jpct-ae, android-2.3.3, loadTexture error: Out of memory  (Read 3813 times)

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
jpct-ae, android-2.3.3, loadTexture error: Out of memory
« on: July 16, 2012, 03:15:01 pm »
Hi all:

  I used a 2048*2048 jpg for texture, then app crashed. Android-logcat info like this:


07-16 20:36:12.671: I/jPCT-AE(4846): Loading Texture...
07-16 20:36:12.703: D/dalvikvm(4846): GC_FOR_MALLOC freed <1K, 47% free 2921K/5447K, external 9811K/11859K, paused 25ms

07-16 20:36:12.765: I/dalvikvm-heap(4846): Grow heap (frag case) to 30.800MB for 16777232-byte allocation

07-16 20:36:12.796: D/dalvikvm(4846): GC_FOR_MALLOC freed 0K, 12% free 19305K/21895K, external 9811K/11859K, paused 24ms

07-16 20:36:12.820: I/jPCT-AE(4846): Texture loaded...16777216 bytes/2048*2048 pixels!

07-16 20:36:12.906: D/dalvikvm(4846): GC_CONCURRENT freed 1K, 12% free 19304K/21895K, external 9811K/11859K, paused 3ms+4ms
07-16 20:36:13.093: I/jPCT-AE(4846): Memory usage before compacting: 19306 KB used out of 21895 KB. Max. memory available to the VM is 49152 KB.
07-16 20:36:13.132: D/dalvikvm(4846): GC_EXPLICIT freed 1K, 12% free 19306K/21895K, external 9811K/11859K, paused 38ms
07-16 20:36:13.171: D/dalvikvm(4846): GC_EXPLICIT freed <1K, 12% free 19306K/21895K, external 9811K/11859K, paused 38ms
07-16 20:36:13.328: I/jPCT-AE(4846): Memory usage after compacting: 19306 KB used out of 21895 KB. Max. memory available to the VM is 49152 KB.
07-16 20:36:14.132: I/jPCT-AE(4846): Subobject of object 0/object2 compiled to flat fixed point data using 1704 vertices in 230ms!
07-16 20:36:14.140: I/jPCT-AE(4846): Object 0/object2 compiled to 1 subobjects in 808ms!
07-16 20:36:14.140: I/jPCT-AE(4846): Object 'object2' uses one texture set!
07-16 20:36:14.187: D/dalvikvm(4846): GC_EXTERNAL_ALLOC freed 98K, 12% free 19296K/21895K, external 9864K/11859K, paused 41ms
07-16 20:36:14.242: D/dalvikvm(4846): GC_EXTERNAL_ALLOC freed 0K, 12% free 19296K/21895K, external 9864K/11859K, paused 40ms
07-16 20:36:14.273: I/dalvikvm-heap(4846): Clamp target GC heap from 48.845MB to 48.000MB
07-16 20:36:14.289: D/dalvikvm(4846): GC_FOR_MALLOC freed 0K, 12% free 19296K/21895K, external 26248K/28296K, paused 26ms
07-16 20:36:14.382: D/dalvikvm(4846): GC_FOR_MALLOC freed <1K, 12% free 19296K/21895K, external 18056K/26248K, paused 25ms

07-16 20:36:14.382: I/dalvikvm-heap(4846): Forcing collection of SoftReferences for 16777232-byte allocation

07-16 20:36:14.414: D/dalvikvm(4846): GC_FOR_MALLOC freed 0K, 12% free 19296K/21895K, external 18056K/26248K, paused 28ms

07-16 20:36:14.414: E/dalvikvm-heap(4846): Out of memory on a 16777232-byte allocation.

07-16 20:36:14.414: I/dalvikvm(4846): "GLThread 10" prio=5 tid=9 RUNNABLE
07-16 20:36:14.414: I/dalvikvm(4846):   | group="main" sCount=0 dsCount=0 obj=0x4051ca80 self=0x2a9410
07-16 20:36:14.414: I/dalvikvm(4846):   | sysTid=4855 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=2790728
07-16 20:36:14.414: I/dalvikvm(4846):   at com.threed.jpct.GLRenderer.convertTexture(GLRenderer.java:~845)
07-16 20:36:14.414: I/dalvikvm(4846):   at com.threed.jpct.GLRenderer.setTextures(GLRenderer.java:2270)
07-16 20:36:14.414: I/dalvikvm(4846):   at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2195)
07-16 20:36:14.414: I/dalvikvm(4846):   at com.threed.jpct.World.draw(World.java:1307)
07-16 20:36:14.414: I/dalvikvm(4846):   at com.threed.jpct.World.draw(World.java:1074)
07-16 20:36:14.421: I/dalvikvm(4846):   at ddd.pd.Demo$MyRenderer.onDrawFrame(Demo.java:231)
07-16 20:36:14.421: I/dalvikvm(4846):   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
07-16 20:36:14.421: I/dalvikvm(4846):   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
07-16 20:36:23.039: W/dalvikvm(4846): threadid=9: thread exiting with uncaught exception (group=0x40015560)
07-16 20:36:23.085: E/AndroidRuntime(4846): FATAL EXCEPTION: GLThread 10
07-16 20:36:23.085: E/AndroidRuntime(4846): java.lang.OutOfMemoryError
07-16 20:36:23.085: E/AndroidRuntime(4846):    at com.threed.jpct.GLRenderer.convertTexture(GLRenderer.java:845)
07-16 20:36:23.085: E/AndroidRuntime(4846):    at com.threed.jpct.GLRenderer.setTextures(GLRenderer.java:2270)
07-16 20:36:23.085: E/AndroidRuntime(4846):    at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2195)
07-16 20:36:23.085: E/AndroidRuntime(4846):    at com.threed.jpct.World.draw(World.java:1307)
07-16 20:36:23.085: E/AndroidRuntime(4846):    at com.threed.jpct.World.draw(World.java:1074)
07-16 20:36:23.085: E/AndroidRuntime(4846):    at ddd.pd.Demo$MyRenderer.onDrawFrame(Demo.java:231)
07-16 20:36:23.085: E/AndroidRuntime(4846):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363)
07-16 20:36:23.085: E/AndroidRuntime(4846):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
07-16 20:41:23.203: I/Process(4846): Sending signal. PID: 4846 SIG: 9




  My code:
       
 
Code: [Select]
       //onSurfaceChanged
      Options options = new Options();
      options.inScaled = false;
      Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.raw.texture, options);
      Texture texture2 = new Texture(bitmap);

     TextureManager.getInstance().addTexture("m", texture2);
      cube.setTexture("m");
      world.addObject(cube);

Can anyone tell me why? And how to resolve it? Why "new Texture(bitmap);" didn't crashed but "World.draw" creashed?

If i use a smaller jpg for texture, then all  are ok.
« Last Edit: July 16, 2012, 03:17:25 pm by kiffa »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: jpct-ae, android-2.3.3, loadTexture error: Out of memory
« Reply #1 on: July 16, 2012, 05:53:13 pm »
Please refer to the wiki's 'reduce memory usage' for more information, but basically 2048*2048 is insane for a mobile device. That texture alone requires up to 36mb, which is a bit too much for a 24mb vm. The crash happens in onDraw because the texture will be transfered to the gpu at that stage which more than doubles its memory needs. There is only one solution: Use smaller textures.

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: jpct-ae, android-2.3.3, loadTexture error: Out of memory
« Reply #2 on: July 17, 2012, 05:03:38 am »
Thanks!

I like Jpct-AE  because of its simple and performance. And there is another question:
 
  I tried JME3(Jmonkey) engine, to do the same thing, use the same texture(2048*2048) and the same obj、mtl and the same phone,but didn't crash.

  Is there any difference between  Jpct-AE and JME3 (to handle texture)?

 

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: jpct-ae, android-2.3.3, loadTexture error: Out of memory
« Reply #3 on: July 17, 2012, 07:14:42 am »
Either it doesn't load the texture in that size and scales it down or it compresses it somehow (16bit, ETC1...whatever...you can do that with jPCT-AE too). You simply can't upload a 2048*2048=16mb texture on a 2.3 based vm...it just doesn't fit into vm memory.