Author Topic: Loading big models (memory issues)  (Read 8909 times)

Offline thiamant

  • byte
  • *
  • Posts: 19
    • View Profile
Loading big models (memory issues)
« on: September 10, 2010, 01:10:13 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Loading big models (memory issues)
« Reply #1 on: September 10, 2010, 01:22:54 pm »
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?


Offline thiamant

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Loading big models (memory issues)
« Reply #2 on: September 10, 2010, 02:08:23 pm »
Yes, that's the point. I'm already serializing/deserializing the model... (And enabling the reduced mode)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Loading big models (memory issues)
« Reply #3 on: September 10, 2010, 02:20:46 pm »
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)?

Offline thiamant

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Loading big models (memory issues)
« Reply #4 on: September 10, 2010, 02:27:06 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Loading big models (memory issues)
« Reply #5 on: September 10, 2010, 09:47:44 pm »
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?

Offline thiamant

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Loading big models (memory issues)
« Reply #6 on: September 11, 2010, 12:28:07 pm »
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.

Offline thiamant

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Loading big models (memory issues)
« Reply #7 on: September 13, 2010, 05:19:39 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Loading big models (memory issues)
« Reply #8 on: September 13, 2010, 10:41:35 pm »
Do you have a log output to see what exactly happens before this crash?

Offline thiamant

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Loading big models (memory issues)
« Reply #9 on: September 14, 2010, 03:37:34 pm »
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.
« Last Edit: September 15, 2010, 08:25:47 pm by thiamant »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Loading big models (memory issues)
« Reply #10 on: September 15, 2010, 09:01:59 am »
The complete log (not just the exception) might help too.

Offline thiamant

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Loading big models (memory issues)
« Reply #11 on: September 15, 2010, 08:26:11 pm »
Edited the post with additional information

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Loading big models (memory issues)
« Reply #12 on: September 16, 2010, 08:16:18 am »
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... ???
« Last Edit: September 16, 2010, 08:43:17 am by EgonOlsen »

Offline thiamant

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Loading big models (memory issues)
« Reply #13 on: September 20, 2010, 12:50:28 pm »
There's no jPCT lines that show any error at all. Anyway, we've reduced the model and it's working ok now.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Loading big models (memory issues)
« Reply #14 on: September 25, 2010, 10:24:06 pm »
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.