Loading big models (memory issues)

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

Previous topic - Next topic

iagofg

I'm also getting that problem relating this, appears that the apk access allows only to objects bellow 1MB in size... here is my exception:

09-10 22:17:48.435: INFO/jPCT-AE(373): Loading Texture...
09-10 22:17:48.465: INFO/jPCT-AE(373): Loading Texture...
09-10 22:17:48.465: INFO/jPCT-AE(373): onSurfaceChanged
09-10 22:17:48.508: INFO/jPCT-AE(373): OpenGL vendor:     Android
09-10 22:17:48.508: INFO/jPCT-AE(373): OpenGL renderer:   Android PixelFlinger 1.3
09-10 22:17:48.508: INFO/jPCT-AE(373): OpenGL version:    OpenGL ES-CM 1.0
09-10 22:17:48.508: INFO/jPCT-AE(373): OpenGL renderer initialized (using 2 texture stages)
09-10 22:17:48.948: INFO/ARMAssembler(373): generated scanline__00000077:03545444_00009501_00000000 [142 ipp] (195 ins) at [0x284ad8:0x284de4] in 49500022 ns
09-10 22:17:49.015: INFO/ActivityManager(59): Displayed activity com.gargore.zpunch/.ZPunchActivity: 5059 ms (total 5059 ms)
09-10 22:17:49.025: WARN/KeyCharacterMap(373): No keyboard for id 0
09-10 22:17:49.106: WARN/KeyCharacterMap(373): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
09-10 22:17:52.855: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@450e4058
09-10 22:17:57.666: WARN/InputManagerService(59): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44fe6750
09-10 22:17:57.676: DEBUG/asset(373): Data exceeds UNCOMPRESS_DATA_MAX (4071780 vs 1048576)
09-10 22:17:57.676: WARN/System.err(373): java.io.IOException
09-10 22:17:57.925: WARN/System.err(373):     at android.content.res.AssetManager.readAsset(Native Method)
09-10 22:17:57.995: WARN/System.err(373):     at android.content.res.AssetManager.access$700(AssetManager.java:36)
09-10 22:17:57.995: WARN/System.err(373):     at android.content.res.AssetManager$AssetInputStream.read(AssetManager.java:574)
09-10 22:17:57.995: WARN/System.err(373):     at com.threed.jpct.DeSerializer.read(DeSerializer.java:439)
09-10 22:17:57.995: WARN/System.err(373):     at com.threed.jpct.DeSerializer.readInt(DeSerializer.java:423)
09-10 22:17:57.995: WARN/System.err(373):     at com.threed.jpct.DeSerializer.deserialize(DeSerializer.java:29)
09-10 22:17:57.995: WARN/System.err(373):     at com.threed.jpct.Loader.loadSerializedObject(Loader.java:97)
09-10 22:17:57.995: WARN/System.err(373):     at com.gargore.zpunch.ZPunchActivity$2.run(ZPunchActivity.java:412)
09-10 22:17:57.995: INFO/jPCT-AE(373): [ 1315693078000 ] - ERROR: Can't deserialize object: null
09-10 22:17:57.995: WARN/System.err(373): java.lang.RuntimeException: [ 1315693078000 ] - ERROR: Can't deserialize object: null
09-10 22:17:58.025: WARN/System.err(373):     at com.threed.jpct.Logger.log(Logger.java:189)
09-10 22:17:58.025: WARN/System.err(373):     at com.threed.jpct.DeSerializer.deserialize(DeSerializer.java:201)
09-10 22:17:58.025: WARN/System.err(373):     at com.threed.jpct.Loader.loadSerializedObject(Loader.java:97)
09-10 22:17:58.025: WARN/System.err(373):     at com.gargore.zpunch.ZPunchActivity$2.run(ZPunchActivity.java:412)
09-10 22:17:58.035: WARN/dalvikvm(373): threadid=8: thread exiting with uncaught exception (group=0x4001d800)
09-10 22:17:58.085: ERROR/AndroidRuntime(373): FATAL EXCEPTION: Thread-9
09-10 22:17:58.085: ERROR/AndroidRuntime(373): java.lang.RuntimeException: java.lang.RuntimeException: [ 1315693078000 ] - ERROR: Can't deserialize object: null
09-10 22:17:58.085: ERROR/AndroidRuntime(373):     at com.gargore.zpunch.ZPunchActivity$2.run(ZPunchActivity.java:418)
09-10 22:17:58.085: ERROR/AndroidRuntime(373): Caused by: java.lang.RuntimeException: [ 1315693078000 ] - ERROR: Can't deserialize object: null
09-10 22:17:58.085: ERROR/AndroidRuntime(373):     at com.threed.jpct.Logger.log(Logger.java:189)
09-10 22:17:58.085: ERROR/AndroidRuntime(373):     at com.threed.jpct.DeSerializer.deserialize(DeSerializer.java:201)
09-10 22:17:58.085: ERROR/AndroidRuntime(373):     at com.threed.jpct.Loader.loadSerializedObject(Loader.java:97)
09-10 22:17:58.085: ERROR/AndroidRuntime(373):     at com.gargore.zpunch.ZPunchActivity$2.run(ZPunchActivity.java:412)
09-10 22:17:58.266: WARN/ActivityManager(59):   Force finishing activity com.gargore.zpunch/.ZPunchActivity
09-10 22:17:58.326: INFO/jPCT-AE(373): onPause
09-10 22:18:00.135: INFO/jPCT-AE(373): onStop
09-10 22:18:01.295: DEBUG/dalvikvm(302): GC_EXPLICIT freed 905 objects / 60472 bytes in 4548ms
09-10 22:18:01.845: INFO/Process(373): Sending signal. PID: 373 SIG: 9
09-10 22:18:02.782: INFO/ActivityManager(59): Process com.gargore.zpunch (pid 373) has died.

Seems the cause is on:
09-10 22:17:57.676: DEBUG/asset(373): Data exceeds UNCOMPRESS_DATA_MAX (4071780 vs 1048576)

What I don't understand is why the serialized file is so big (I yet put it on reduced mode and the source .obj files total size are less than 2mb, with all the geometry and wavefront files waste a lot of space, I also merged the geometry for generate animation like in http://www.jpct.net/wiki/index.php/Loading_3ds_Keyframes_from_Blender but with obj files.

Maybe there is something else to do? (the model is yet reduced).

I'm thinking on implement my own stream filter to store in parts the big serialized file...

iagofg

I've workaround yet my own InputStream child class that loads model form splitted file successfully.

It is a minefield test-only yet, but works and perhaps helps someone (I tried with BufferedInputStream but Loader seems not to be compatible):

   //zp = Loader.loadSerializedObject(res.openRawResource(R.raw.zpmodel));
   zp = Loader.loadSerializedObject(new MyModelStream());
   
   [...]
   
   class MyModelStream extends java.io.InputStream {
      private int i = 0;
      private java.io.InputStream s = null;
      private void changestream() {
         ++i;
         //Log.v(TAG, "MyModelStream reading resource file no. " + i);
         if (i == 1) s = getResources().openRawResource(R.raw.zpmodel_aa);
         if (i == 2) s = getResources().openRawResource(R.raw.zpmodel_ab);
         if (i == 3) s = getResources().openRawResource(R.raw.zpmodel_ac);
         if (i == 4) s = getResources().openRawResource(R.raw.zpmodel_ad);
      }
      public int available() throws IOException {
         if (s == null) changestream();
         if (s == null) return 0;
         int v = s.available();
         if (v <= 0) { // needs to change stream here also for Loader compat
            //Log.v(TAG, "MyModelStream.available returns <= 0, next block and requesting again...");
            changestream();
            v = s.available();
         }
         //Log.v(TAG, "MyModelStream.available returns " + v);
         return v;
      }
      public void close() throws IOException {
         if (s == null) changestream();
         if (s == null) return;
         //Log.v(TAG, "MyModelStream.close has been called");
         s.close();
      }
      public void mark(int readlimit) {
         //Log.v(TAG, "MyModelStream.mark has been called");
         return;
      }
      public boolean markSupported() {
         boolean v = false;
         //Log.v(TAG, "MyModelStream.markSupported returns " + v);
         return v;
      }
      public int read() throws IOException {
         if (s == null) changestream();
         if (s == null) return -1;
         int v = s.read();
         if (v < 0) {
            //Log.v(TAG, "MyModelStream.read returns < 0, next block and reading again...");
            changestream();
            v = s.read();
         }
         //Log.v(TAG, "MyModelStream.read returns " + v + " bytes");
         return v;
      }
      public int read(byte[] b) throws IOException, NullPointerException {
         if (s == null) changestream();
         if (s == null) return -1;
         int v = s.read(b);
         if (v < 0) {
            //Log.v(TAG, "MyModelStream.read returns < 0, next block and reading again...");
            changestream();
            v = s.read(b);
         }
         //Log.v(TAG, "MyModelStream.read returns " + v + " bytes");
         return v;
      }
      public int read(byte[] b, int off, int len) throws IOException, NullPointerException {
         if (s == null) changestream();
         if (s == null) return -1;
         int v = s.read(b, off, len);
         if (v < 0) {
            //Log.v(TAG, "MyModelStream.read returns < 0, next block and reading again...");
            changestream();
            v = s.read(b, off, len);
         }
         //Log.v(TAG, "MyModelStream.read returns " + v + " bytes");
         return v;
      }
      public void reset() throws IOException {
         //Log.v(TAG, "MyModelStream.reset has been called");
         throw new IOException();
      }
      public long skip(long n) throws IOException {
         if (s == null) changestream();
         if (s == null) return 0;
         long v = s.skip(n);
         //Log.v(TAG, "MyModelStream.skip returns " + v);
         return v;
      }
   }

EgonOlsen

Just rename the file to .mp3 and these restrictions will go away.