the3deer / android-3D-model-viewer

Android OpenGL 2.0 application to view 3D models. Published on Play Store
https://play.google.com/store/apps/details?id=org.andresoviedo.dddmodel2
MIT License
1.44k stars 380 forks source link

Crash reloading Big Models #183

Open MonikaMoon opened 3 years ago

MonikaMoon commented 3 years ago

I am creating a 3D model using multiple .stl files. I have updated STLLoaderTask according to my requirement to load multiple .stl files. I also have to add colors, but my model is not rendered correctly with colors. Its getting created for the first time but when I reload the model, my app is crashing with following errors: Caused by: java.lang.OutOfMemoryError: Failed to allocate a 65431423 byte allocation with 25165824 free bytes and 42MB until OOM, max allowed footprint 517468552, growth limit 536870912 at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at java.nio.DirectByteBuffer$MemoryRef.(DirectByteBuffer.java:71) at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:257) at org.andresoviedo.util.io.IOUtils.createNativeByteBuffer(IOUtils.java:64) at org.andresoviedo.util.io.IOUtils.createFloatBuffer(IOUtils.java:43) at org.andresoviedo.android_3d_model_engine.services.collada.entities.MeshData.getVertexBuffer(MeshData.java:714) at com.movechair.modules.main.analysis.ThreeDModel.STLLoaderTask.build(STLLoaderTask.java:213) at org.andresoviedo.android_3d_model_engine.services.LoaderTask.doInBackground(LoaderTask.java:67) at org.andresoviedo.android_3d_model_engine.services.LoaderTask.doInBackground(LoaderTask.java:19) at android.os.AsyncTask$2.call(AsyncTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:246)  at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)  at java.lang.Thread.run(Thread.java:784) 

Please help me with this error.

jamesbellaero commented 3 years ago

When debugging, always check the top first.

This one seems pretty simple - your phone ran out of memory. Try reducing model complexity.

MonikaMoon commented 3 years ago

@jamesbellaero What exactly do you mean by reducing model complexity? My requirement is to render 3D model using multiple .stl file, I can not optimize it more. Is there any way to clear cache or Object3D while reloading the model?

jamesbellaero commented 3 years ago

Perhaps you need to think about the issue differently. I don't know your use case, but generally when people want to render multiple 3D models they're doing video or game production

For videos and scene rendering, people use computers with 64+ GB of RAM and another TB of swap space.

For games, a lot of optimization is performed to reduce model size and render only the necessary components. I would not use this tool for games because I would not use .stl's for games.