I’m currently exploring the Babylon Native library on Android and have run into a tricky issue that I haven’t been able to solve.
My app allows users to select from a list of .glb files and view them in a separate Activity using BabylonView. The first time I launch the Activity, everything works fine — the selected model is loaded and rendered correctly.
The problem comes when I exit the Activity and select a different .glb. When the Activity restarts, it still shows the previous scene, even though I’m updating the path and attempting to load a new file.
I’ve tried cleaning things up in onStop() and onDestroy() using:
Just a few thoughts.
You append a new scene to an engine that just destroyed the original scene, maybe the append gets confused? Why not loadAsync the new scene.
The loader you use is deprecated and the replacement is a much better loader. (Check the documentation for it)
Does your mView.loadscript fires the second time? Maybe a caching thing.
I’ve tried with and without the scene.dispose() and engine.dispose functions.
Without calling those, the previously loaded scene stills play, but if I dispose of the engine and/or the scene, nothing happens (I just have a black screen or the previous scene that’s frozen).
The mView.loadscript() function is called the second time (the Android logs show that this part of the code runs as expected), but the JS code isn’t executed (the JS logs don’t appear the second time).
Concerning the deprecated function,
I should then replace BABYLON.SceneLoader.AppendAsync(path) by BABYLON.AppendSceneAsync("path/to/model", scene);. Is it the ‘module level function’ to use as recommended here: https://doc.babylonjs.com/typedoc/classes/BABYLON.SceneLoader ?
The logs show that the path are as expected, and I still have a default file path in case it is not the case.
I’ve tried adding the scene.dispose() before the AppendAsync, but, I still end up with the same result, it seems that once I’ve left the Activity, the mView.loadScript() method don’t work anymore.