Author Topic: AdvancedExample OutOfMemoryError  (Read 3819 times)

Offline Simdanfeg

  • byte
  • *
  • Posts: 41
    • View Profile
AdvancedExample OutOfMemoryError
« on: May 24, 2011, 03:46:08 am »
 ::),when i test the example AdvancedExample,i occur the OutOfMemoryError,i try to check it ,and found if load the format md2(after create plane ,rock,not create sky) ,this situation will be encountered.i also setting some parameters. e.g  call forceGeometryIndices() before build() and call strip().  also called the method Texture.defaultTo4bpp(true).
btw : I reduced the size of the picture
there is my error message
Code: [Select]
05-24 01:26:29.331: ERROR/AndroidRuntime(997): java.lang.OutOfMemoryError
05-24 01:26:29.331: ERROR/AndroidRuntime(997):     at org.apache.harmony.luni.platform.OSMemory.malloc(Native Method)
05-24 01:26:29.331: ERROR/AndroidRuntime(997):     at org.apache.harmony.luni.platform.PlatformAddressFactory.alloc(PlatformAddressFactory.java:129)
05-24 01:26:29.331: ERROR/AndroidRuntime(997):     at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:65)
05-24 01:26:29.331: ERROR/AndroidRuntime(997):     at java.nio.ReadWriteDirectByteBuffer.<init>(ReadWriteDirectByteBuffer.java:48)
05-24 01:26:29.331: ERROR/AndroidRuntime(997):     at java.nio.BufferFactory.newDirectByteBuffer(BufferFactory.java:93)
05-24 01:26:29.331: ERROR/AndroidRuntime(997):     at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:65)
05-24 01:26:29.331: ERROR/AndroidRuntime(997):     at com.threed.jpct.GLRenderer.getTextureStages(GLRenderer.java:1535)
05-24 01:26:29.331: ERROR/AndroidRuntime(997):     at com.threed.jpct.GLRenderer.init(GLRenderer.java:469)
05-24 01:26:29.331: ERROR/AndroidRuntime(997):     at com.threed.jpct.FrameBuffer.<init>(FrameBuffer.java:82)
05-24 01:26:29.331: ERROR/AndroidRuntime(997):     at sim.feel.MyRenderer.onSurfaceChanged(MyRenderer.java:107)
05-24 01:26:29.331: ERROR/AndroidRuntime(997):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1356)
05-24 01:26:29.331: ERROR/AndroidRuntime(997):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: AdvancedExample OutOfMemoryError
« Reply #1 on: May 24, 2011, 10:21:25 am »
MD2 is a bloated format. You'll run into memory constraints when using it naively pretty quickly especially on those older phones/VMs, who are limited to 16mb. If you want to use it, the better way is to load the model using desktop jPCT, remove the sequences from the animation that you don't need and save the result via the DeSerializer class.

Offline Simdanfeg

  • byte
  • *
  • Posts: 41
    • View Profile
Re: AdvancedExample OutOfMemoryError
« Reply #2 on: May 24, 2011, 02:29:47 pm »
I do not understand the "remove the sequences from the animation that you don't need and save the result via the DeSerializer class"
hope you give a brief introduction about it,thank you very much  ;D

Offline Simdanfeg

  • byte
  • *
  • Posts: 41
    • View Profile
Re: AdvancedExample OutOfMemoryError
« Reply #3 on: May 24, 2011, 02:48:10 pm »
eh,i borrow my classmate's HD2, :D,running,So excited.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: AdvancedExample OutOfMemoryError
« Reply #4 on: May 24, 2011, 04:24:22 pm »
Well, something like this:
Code: [Select]

TextureManager.getInstance().addTexture("alien", new Texture("alienskin.jpg"));
Object3D alien= Loader.loadMD2("alien.md2", 0.8f);
alien.setTexture("alien");
alien.compile(true);
alien.build();

alien.getAnimationSequence().remove(3);
alien.getAnimationSequence().remove(4);
alien.getAnimationSequence().remove(6);
alien.getAnimationSequence().remove(7);

// ....remove all unneeded sequences here...

new DeSerializer().serialize(alien, new FileOutputStream("alien.ser"), true);

You can then take that alien.ser file and load it on Android via the Loader-class. To figure out which animations you need, you can use any MD2 viewer...or write a simple one yourself.

Offline Simdanfeg

  • byte
  • *
  • Posts: 41
    • View Profile
Re: AdvancedExample OutOfMemoryError
« Reply #5 on: May 25, 2011, 02:41:51 am »
i see, I will try, thank you ;)