Loading big models (memory issues)

Started by thiamant, September 10, 2010, 01:10:13 PM

Previous topic - Next topic

thiamant

I'm trying to load a model with a reasonable size and it's working more or less properly (maybe at a low frame rate which is around 10 atm) in my orange boston. The app crashes in HTC Desire though. I think this is happening due to some memory issues (maybe a limited heap size). So, how exactly is the model being loaded (is jpct loading the .obj completely in memory and uncompressed? the obj size is just around 3-4MB and it's uncompressed but clearly the heap size is larger than 4 MB).

Can I load the model in several parts so only the parts needed are stored in memory?
Do you think I could have to optimize the model to make it work properly? What are my chances here?

EgonOlsen

Don't load these models directly in AE. Load them in desktop jPCT and serialize them in reduced mode: (http://www.jpct.net/wiki/index.php/Differences_between_jPCT_and_jPCT-AE#Performance_and_memory_issues.2C_serialized_objects).

Or are you already doing that and it's still hitting the memory barrier?


thiamant

Yes, that's the point. I'm already serializing/deserializing the model... (And enabling the reduced mode)

EgonOlsen

Are you sure then that the crash is related to low memory? Can you provide me with the model to see for myself (preferably the "normal" and the serialized version is possible)?

thiamant

I'm sorry but im under NDA and can't show these models. But in the emulator it crashes due to an OutOfMemoryException. I have to launch the emulator with 256 MB RAM and max heap size of around 128 MB to make it work, and I think that htc desire has lower heap size allowed.

EgonOlsen

When comparing the specs of the orange boston and the htc desire, the desire is actually the more advanced phone, isn't it? Older Android version like 1.5/1.6 have a usable heap size of around 12mb, never versions like 2.2 should have something around 20mb. I don't see why something that loads fine on the boston should fail on the desire!?

How are you loading the textures? As drawables or as raws? How big are they? Have you tried what happens if you omit loading them?

thiamant

I've already tried to load the model without textures and it still crashes on htc desire.

I will try to perform a debug on this one and see what happens.

thiamant

I've found out that this is a problem with the android version. Using the same hardware specifications in the emulator and running both 1.6 and 2.1 versions the program crashes only on 2.1 due to OutOfMemoryException, which seems kind of weird. Any ideas?

EgonOlsen

Do you have a log output to see what exactly happens before this crash?

thiamant

#9
This is the exception that is causing the crash:

09-14 19:31:48.118: ERROR/mm-camera(57): +++ DELETING LEAKED MEMORY AT 0x2a980 (2 REMAINING)
09-14 19:31:48.118: ERROR/mm-camera(57):      6 0xa942ba44
09-14 19:31:48.118: ERROR/mm-camera(57):      5 0xa940bfc2
09-14 19:31:48.118: ERROR/mm-camera(57):      4 0xa940d768
09-14 19:31:48.118: ERROR/mm-camera(57):      3 0xa940d27e
09-14 19:31:48.118: ERROR/mm-camera(57):      2 0xafe10074
09-14 19:31:48.118: ERROR/mm-camera(57):      1 0xafe0fb48
09-14 19:31:48.118: ERROR/mm-camera(57): +++ DELETING LEAKED MEMORY AT 0x2a580 (1 REMAINING)
09-14 19:31:48.118: ERROR/mm-camera(57):      6 0xa942ba44
09-14 19:31:48.118: ERROR/mm-camera(57):      5 0xa940bfc2
09-14 19:31:48.118: ERROR/mm-camera(57):      4 0xa940d768
09-14 19:31:48.118: ERROR/mm-camera(57):      3 0xa940d27e
09-14 19:31:48.118: ERROR/mm-camera(57):      2 0xafe10074
09-14 19:31:48.118: ERROR/mm-camera(57):      1 0xafe0fb48
09-14 19:38:20.528: ERROR/AndroidRuntime(10181): ERROR: thread attach failed
09-14 19:38:21.968: ERROR/AndroidRuntime(10196): ERROR: thread attach failed
09-14 19:38:22.958: ERROR/PackageInstallationReceiver(8167): Remove /data/local/tmp/com.jpct.apk Fail!
09-14 19:38:36.628: ERROR/dalvikvm-heap(10208): 288000-byte external allocation too large for this process.
09-14 19:38:36.638: ERROR/dalvikvm(10208): Out of memory: Heap Size=12487KB, Allocated=9857KB, Bitmap Size=3894KB
09-14 19:38:36.668: ERROR/AndroidRuntime(10208): Uncaught handler: thread GLThread 7 exiting due to uncaught exception
09-14 19:38:36.718: ERROR/AndroidRuntime(10208): java.lang.OutOfMemoryError
09-14 19:38:36.718: ERROR/AndroidRuntime(10208):     at org.apache.harmony.luni.platform.OSMemory.malloc(Native Method)
09-14 19:38:36.718: ERROR/AndroidRuntime(10208):     at org.apache.harmony.luni.platform.PlatformAddressFactory.alloc(PlatformAddressFactory.java:145)
09-14 19:38:36.718: ERROR/AndroidRuntime(10208):     at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:67)
09-14 19:38:36.718: ERROR/AndroidRuntime(10208):     at java.nio.ReadWriteDirectByteBuffer.<init>(ReadWriteDirectByteBuffer.java:51)
09-14 19:38:36.718: ERROR/AndroidRuntime(10208):     at java.nio.BufferFactory.newDirectByteBuffer(BufferFactory.java:95)
09-14 19:38:36.718: ERROR/AndroidRuntime(10208):     at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:71)
09-14 19:38:36.718: ERROR/AndroidRuntime(10208):     at com.threed.jpct.CompiledInstance.fill(CompiledInstance.java:662)
09-14 19:38:36.718: ERROR/AndroidRuntime(10208):     at com.threed.jpct.Object3DCompiler.compile(Object3DCompiler.java:134)
09-14 19:38:36.718: ERROR/AndroidRuntime(10208):     at com.threed.jpct.World.compile(World.java:2021)
09-14 19:38:36.718: ERROR/AndroidRuntime(10208):     at com.threed.jpct.World.renderScene(World.java:1057)
09-14 19:38:36.718: ERROR/AndroidRuntime(10208):     at com.jpct.Main$MyRenderer.onDrawFrame(Main.java:410)
09-14 19:38:36.718: ERROR/AndroidRuntime(10208):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1136)
09-14 19:38:36.718: ERROR/AndroidRuntime(10208):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:977)
09-14 19:38:42.038: ERROR/ActivityManager(83): fail to set top app changed!

This happens when calling world.renderScene(fb) for the first time.

EgonOlsen

The complete log (not just the exception) might help too.

thiamant

Edited the post with additional information

EgonOlsen

#12
What's mm-camera and why is it giving all these strange messages? Can't you post the complete log wrapped in code-tags. I'm still not seeing a single jPCT related line... ???

thiamant

There's no jPCT lines that show any error at all. Anyway, we've reduced the model and it's working ok now.

EgonOlsen

However, i tried to load the model you provided with 1.5 on the actual phone and 2.1 and 2.2 in the emulator (Both with default setting, i.e. no heap adjustments made). All loaded fine, so i can't reproduce this problem. If native memory size (and not java heap size) is the actual problem (and it looks like it), it may help to do a <yourObject>.forceGeometryIndicies(true);...but that will make the compilation process much slower in return. It will use less native memory though.