I have created a scene with a few custom mesh objects. My scene with custom meshes reloads and crashes when I open the application on my phone browsers (chrome, safari, brave). My scene loads my 3d objects one at a time. My scene utilizes Assets Manager, my objects are added as tasks to Assets Manager, and Assets Manager loads after each object is added as a task. For my iPhone 8, the crash happens when I load my 3rd object. For my iPhone 12, the crash happens with I load my 5th object. My desktop have no problems loading all my objects one after another.
I believe I have narrowed down the problem to the rendering of the objects after the load. I created a simple scene utilizing one Assets Manager load function execution. My scene crashes on iPhone 8 browsers when I call Assets Manager to load 3 tasks. My scene crashes on iPhone 12 browsers when I call Assets Manager to load 5 tasks. The browser window reloads and/or crashes after those objects are added to the scene. My scene will some times load all the objects, but crashes on interaction.
At first, I suspected that it had to do with the size of the objects and created a scene to load small babylon mesh objects. My scene was able to handle the loading of the small babylon mesh objects and not crash on my iPhone 8. I replaced the small babylon mesh objects with much large babylon assets in my scene and was able to load the scene with the large babylon assets(total size of large babylon assets 2x the total of my custom mesh objects). I was able to interact with the scene with large babylon assets. This led me to believe that it is not precisely a size different issue.
I also tried a few optimization techniques from Optimizing Your Scene | Babylon.js Documentation. I implemented scene.freezeActiveMeshes() and mesh.freezeWorldMatrix() on my objects after the loading. I also assigned scene.autoClear = false and scene.autoClearDepthAndStencil = false. This was not effective in preventing the crash on my iPhone 8.
This seems really hard to troubleshoot without a repro.
It would be great if you could find a playground that reproes the crash. I am guessing it could be large texture more than 2k * 2k or relying on some features Safari is having trouble with (and there are a lot in Safari 15…)
Tested ok on my iphone11. latest ios with safari. Is there anything special to do? I kept it running for some minutes. Nothing relevant in the console.
i loaded the scene on desktop , in the inspector i see 249 textures. I wonder if this is part of the issue. Babylon does not automatically keep single instances of materials with same names. I found this out the hard way and actually wrote some code while loading assets to facilitate having only one instance of a material in the scene. So if an asset loads and it has materials with same names as materials already in the scene , i assign those materials to it and dispose the loaded ones. There is a post with the code here in the forums , worth a shot?
Thank you very much for your reply. I think the amount of textures and materials have something to do with the crash as well. Would you mind sharing that forum post with me?
@sebavan My goal is not to load the same model over and over again. I was trying to create a playground that would mimic my scene crash. My scene has multiple mesh objects and loads all of them eventually. I do have a high amount of textures and materials, which may be causing the mobile crash.
@sebavan Original, I load the models in a queue format with Assets Manager in my current scene. I get the crash loading after loading the 3rd model into the scene on my iphone 8 and the crash occurs on the 5th model load on an iphone 12. I think this narrows it down to textures. Thank you very much for your help and guidance.
Texture is the biggest factor causing phone browser crashing. I also met this condition and now tring to solve it. When I load several assets (.babylon files), my iphone 12 would crash. But if I delete the related textures, it works smoothly.
And now my goal is to load textures manually after meshes are loaded. if there are some ways to control texture loading when we apply BABYLON.SceneLoader.Append or BABYLON.AssetsManager, this problem would be solved. @sebavan@jamesgjwu