loading large OBJ File

Started by gaurav, August 27, 2014, 07:43:15 AM

Previous topic - Next topic

gaurav

i am trying to load large obj file (12mb) but app is crashing . but same code is working to load obj file having 1 mb

My code is

File sdRoot = Environment.getExternalStorageDirectory();
            File file = new File(sdRoot+ "/WatchApp/12345.obj");
            InputStream inputStream = null;
            try {
               inputStream = new FileInputStream(file);
            } catch (FileNotFoundException e1) {
               // TODO Auto-generated catch block
               e1.printStackTrace();
            }
            cube = Object3D.mergeAll(Loader.loadOBJ(inputStream, null, 5f));

cube.build();

            world.addObject(cube);

EgonOlsen

Yes, most likely because is too large and you run into an out of memory error. "is crashing" is of the same quality as "doesn't work"...nobody can derive anything from that description. Please post a stack trace or at least an error message.
However, in this case, it's most likely a simple out of memory. There's not much you can do about this. You can increase the memory on newer devices by adding

android:largeHeap="true"

to your manifest file, but that only cures the symptoms. Personally, i would consider a 12mb file to be too large for a mobile device anyway. If you absolutely have to use it, have a look at serialized objects: http://www.jpct.net/wiki/index.php/Differences_between_jPCT_and_jPCT-AE#Performance_and_memory_issues.2C_serialized_objects

gaurav

#2
Logcat :
    08-27 12:44:59.225: I/jPCT-AE(3387): OpenGL renderer initialized (using 2/8 texture stages)
08-27 12:44:59.230: I/jPCT-AE(3387): Adding Lightsource: 0
08-27 12:44:59.235: I/jPCT-AE(3387): Loading file from InputStream
08-27 12:44:59.530: I/Timeline(3387): Timeline: Activity_idle id: android.os.BinderProxy@41e95420 time:16428502
08-27 12:45:00.210: I/dalvikvm-heap(3387): Forcing collection of SoftReferences for 25022388-byte allocation
08-27 12:45:00.225: E/dalvikvm-heap(3387): Out of memory on a 25022388-byte allocation.
08-27 12:45:00.225: I/dalvikvm(3387): "GLThread 7412" prio=5 tid=12 RUNNABLE
08-27 12:45:00.225: I/dalvikvm(3387):   | group="main" sCount=0 dsCount=0 obj=0x42347a10 self=0x5e31c960
08-27 12:45:00.225: I/dalvikvm(3387):   | sysTid=4091 nice=0 sched=0/0 cgrp=apps handle=1576216776
08-27 12:45:00.225: I/dalvikvm(3387):   | state=R schedstat=( 906733878 74624665 440 ) utm=73 stm=17 core=1
08-27 12:45:00.225: I/dalvikvm(3387):   at java.lang.String.<init>(String.java:~422)
08-27 12:45:00.225: I/dalvikvm(3387):   at java.lang.AbstractStringBuilder.toString(AbstractStringBuilder.java:642)
08-27 12:45:00.225: I/dalvikvm(3387):   at java.lang.StringBuilder.toString(StringBuilder.java:663)
08-27 12:45:00.230: I/dalvikvm(3387):   at com.threed.jpct.Loader.loadBinaryFile(Loader.java:1188)
08-27 12:45:00.230: I/dalvikvm(3387):   at com.threed.jpct.Loader.loadTextFile(Loader.java:78)
08-27 12:45:00.230: I/dalvikvm(3387):   at com.threed.jpct.Loader.loadOBJ(Loader.java:331)
08-27 12:45:00.230: I/dalvikvm(3387):   at com.threed.jpct.Loader.loadOBJ(Loader.java:229)
08-27 12:45:00.230: I/dalvikvm(3387):   at com.emgeesons.watchapp.Model$MyRenderer.onSurfaceChanged(Model.java:431)
08-27 12:45:00.230: I/dalvikvm(3387):   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1514)
08-27 12:45:00.230: I/dalvikvm(3387):   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1242)
08-27 12:45:00.230: I/jPCT-AE(3387): [ 1409123700235 ] - ERROR: Couldn't read file from InputStream
08-27 12:45:00.240: W/dalvikvm(3387): threadid=12: thread exiting with uncaught exception (group=0x41bbfce0)
08-27 12:45:00.240: E/AndroidRuntime(3387): FATAL EXCEPTION: GLThread 7412
08-27 12:45:00.240: E/AndroidRuntime(3387): Process: com.emgeesons.watchapp, PID: 3387
08-27 12:45:00.240: E/AndroidRuntime(3387): java.lang.RuntimeException: [ 1409123700235 ] - ERROR: Couldn't read file from InputStream
08-27 12:45:00.240: E/AndroidRuntime(3387):    at com.threed.jpct.Logger.log(Logger.java:193)
08-27 12:45:00.240: E/AndroidRuntime(3387):    at com.threed.jpct.Loader.loadBinaryFile(Loader.java:1192)
08-27 12:45:00.240: E/AndroidRuntime(3387):    at com.threed.jpct.Loader.loadTextFile(Loader.java:78)
08-27 12:45:00.240: E/AndroidRuntime(3387):    at com.threed.jpct.Loader.loadOBJ(Loader.java:331)
08-27 12:45:00.240: E/AndroidRuntime(3387):    at com.threed.jpct.Loader.loadOBJ(Loader.java:229)


and it crash on this line
cube = Object3D.mergeAll(Loader.loadOBJ(inputStream, null, 5f));

EgonOlsen

As said, it's out of memory


Out of memory on a 25022388-byte allocation.

gaurav

am i doing wrong to load? even android:largeHeap="true" giving same result ..any way avoid this
            

EgonOlsen

Just read the rest of my post above and try to use serialized objects instead. If that still doesn't work, your object is simply too large.

Also make sure that you've used android:largeHeap="true" correctly. I find it hard to believe that it doesn't help unless you are using a pretty old device.

gaurav

#6
i am using gt-i9300(s3) ,running 4.4.4 even i tested on moto G (4.4.4)  ..any tut for using serialized objects

EgonOlsen

The easiest way might be to try the ecplise plugin that the wiki mentions. If that's not an option, you have to do something like this:


  • Download desktop jPCT and unzip it
  • Create a new project in your IDE that includes the desktop jPCT jar
  • Create a new class with a main method in your project and load the model just as you would do it jPCT-AE. You might have to increase heap memory in your project as well to load it.
  • Call build() on the object, create a nw DeSerializer instance and serialize the Object3D in reduced format.
  • Run your class.
  • Copy the resulting file into your Android project.
  • Load it via the Loader class.

EgonOlsen

One addition: You might want to zip the resulting file and load it via a ZipInputStream, because otherwise, it will be pretty large.

gaurav

android:largeHeap="true" is  working , perv i have puted in wrong place .
for 12 mb obj file it took ard 3 min and 2048*2048 texture 1 min so overall it took 4 min to load that model.is it right behaviour

Thanks For help
one more qus can i apply pinch zoom for that obj model ?

EgonOlsen

As said: 12mb is huge for a mobile device. The loading times are reasonable for that size. Use serialized objects to cut them down. That's why they have been invented in the first place.

gaurav

I tired using eclipse plug-in but it requires folder name, i am storing obj file in sd card

gaurav

Still i am not getting how to use  serialized. I knw i am asking too much any sample code is present

EgonOlsen

Quote from: gaurav on August 27, 2014, 03:46:53 PM
I tired using eclipse plug-in but it requires folder name, i am storing obj file in sd card
Just copy the file from the plugin's folder to your sd-card. I fail to see the problem here... ???

EgonOlsen

Quote from: gaurav on August 27, 2014, 04:10:13 PM
Still i am not getting how to use  serialized. I knw i am asking too much any sample code is present
Actually, there isn't much to show. In your serializer project as described above, you simply do:


new DeSerializer().serialize(yourObject3D, someOutputStream, true);


then you copy the result and on Android, you do something like


Loader.loadSerializedObject(someInputStream);


That's basically it.