AdvancedExample OutOfMemoryError

Started by Simdanfeg, May 24, 2011, 03:46:08 AM

Previous topic - Next topic

Simdanfeg

 ::),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

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)


EgonOlsen

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.

Simdanfeg

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

Simdanfeg

eh,i borrow my classmate's HD2, :D,running,So excited.

EgonOlsen

Well, something like this:


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.

Simdanfeg