google / model-viewer

Easily display interactive 3D models on the web and in AR!
https://modelviewer.dev
Apache License 2.0
6.84k stars 807 forks source link

App crash after render many sources #4410

Closed iLStAx closed 1 year ago

iLStAx commented 1 year ago

Description

Hello, we are using the model viewer to render some model dishes (changing only the source) and after maybe 5-6 times changing the source the app crashes, we did a research to figure it out what is going on and the issue was the increment on cache memory when the model viewer render a model (the heap increase every time a model was render). We tried avoid this behavior setting the attribute modelCacheSize to 0 but don't work. Can you help us with this problem please?

Live Demo

https://glitch.com/edit/#!/model-viewer

https://github.com/google/model-viewer/assets/5216703/bb6eba85-c5a1-46d1-9e1e-fb65359cdef1

Version

Browser Affected

OS

AR

elalish commented 1 year ago

That definitely sounds like a memory leak - can you include a link to your site where we can repro? A screenshot of your heap trace would be useful too, just to make sure we're looking at the same thing.

iLStAx commented 1 year ago

@elalish Hello! here is the link to test by yourself https://dev-app.cartear.com/token/ZW50aXR5PUImYnJhbmNoX2lkPTE=/35/product_viewer and the image with the memory usage, by the way this happens at the moment only when you use a phone. Screenshot 2023-08-02 at 03 04 43

elalish commented 1 year ago

I'm not seeing much trend with the JS heap, but the event listeners seem to be increasing. I'd guess that might be happening outside of MV? If you can make a minimal repro that shows it's a MV problem we'll look at it in more detail.

image

Also, those are great models! What process did you use to capture/create them?

elalish commented 1 year ago

Actually, I just checked your site and modelCacheSize is still 5, so I'd guess it's just being set incorrectly. See static property usage here: https://modelviewer.dev/examples/loading/#dracoSupport

Probably the phone is running out of GPU RAM.

iLStAx commented 1 year ago

@elalish How do you get the model cache size? we actually have set at 0 (maybe you go to the older link i attached, sorry my bad) the new link has the property in the right way

image

and this is the way i set the model cache size on the model viewer image

iLStAx commented 1 year ago

I'm not seeing much trend with the JS heap, but the event listeners seem to be increasing. I'd guess that might be happening outside of MV? If you can make a minimal repro that shows it's a MV problem we'll look at it in more detail. image

Also, those are great models! What process did you use to capture/create them?

Thanks 🥳! Is a custom process developed by a partner of mine, he is the creative mind behind the models.

iLStAx commented 1 year ago

I'm not seeing much trend with the JS heap, but the event listeners seem to be increasing. I'd guess that might be happening outside of MV? If you can make a minimal repro that shows it's a MV problem we'll look at it in more detail. image

Also, those are great models! What process did you use to capture/create them?

I only have one listener attached to the model viewer (the load listener) to catch when the model viewer load the model completely 🤔

nicodubi commented 1 year ago

Hello @elalish ! Nice to meet you! I'm Nicolas, CEO of Cartear (https://cartear.com/). I'm glad you liked our models; they are created using photogrammetry techniques, and then we put in a lot of effort to maintain the visual quality of the models while keeping their file size low to ensure a smooth user experience. Cartear's idea is to allow restaurant customers to visualize dishes in 3D and augmented reality while seated, making it easier and safer for them to decide and order. We've been developing Cartear for 3 years, and today we're finally launching it into the market.

Unfortunately, we're facing a problem with the ModelViewer that prevents us from acquiring customers. After showing a few models, the crash that @iLStAx , mentioned occurs. Just to let you know, each model weighs an average of 2 Mb - 3 Mb. As a test, we added a model of a car (which you can see in the link https://dev-app.cartear.com/token/ZW50aXR5PUImYnJhbmNoX2lkPTE=/35/product_viewer that @iLStAx provided) that weighs 49 Mb to see if the crash was due to a cache overflow, but it loads fine. We're puzzled because we've been trying to solve this issue for several days, and it's hindering a normal Cartear launch. This problem occurs on both Android and iPhone devices.

We really appreciate your help and availability to respond. Attached below is a video that reproduces the crash:

https://github.com/google/model-viewer/assets/12632695/8cca84c7-1d6a-4dff-9e67-d6695e1f47bd

Sometimes, what also happens is that before the crash occurs, all the food in the models starts to appear in gray, and then after continuing to load more models, the crash happens:

ModelViewer Bug Previous to Crash

We found that perhaps something related to what @ukito-pl mentioned in this problem issue (https://github.com/google/model-viewer/issues/2000#issuecomment-800953072), where as the load of the models increased, the Leak occurred.

We are looking forward to your comments to find a solution.

Thank you very much again!

elalish commented 1 year ago

@iLStAx No - you're trying to set modelCacheSize as a property, but it's a static property. Please see the link I posted about DRACO - setting static properties is a bit tricky.

Let's test this first and then we'll dig in more if that doesn't fix it.

nicodubi commented 1 year ago

Hi @elalish we saw with @iLStAx that the issue about the crash it was because the images used by textures were 4096 x 4096 px and other images had dimensions that weren't pow of 2. Fixing those things the crash has gone out. Thanks for your help!