With 4.2.0-beta.9 the physics engine in combination with ammo.js seems to be causing the app to freeze or even crash the browser. I am using Firefox on Linux. Babylon.js 4.1.0 works fine. https://playground.babylonjs.com/#Z8JRZ8#1
The playground has random hiccups and restarting it with the play button makes it stop working (physics engine not initialized error).
Adding the following to a scene crashes the browser (“something is slowing down your browser…”)
import * as Ammo from 'ammo.js'
const AmmoLoaded: any = await Ammo()
const gravityVector = new Vector3(0, 0, 0)
const ammoPlugin = new AmmoJSPlugin(true, AmmoLoaded)
scene.enablePhysics(gravityVector, ammoPlugin)
but i see other bug. https://playground.babylonjs.com/#JIGV5V#4 when PG start all works fine but after restart PG with play button see message in console Physics not enabled. its because setInterval async function?
Hi, it indeed seems to be a problem with MeshImposter. For this example I used a sphere but if I import a mesh I would still need the MeshImposter and the problem remains (so not using MeshImposter is not a solution). Also, in 4.1.0 everything works fine.
After some tests, the hiccupps are not random. When creating a mesh impostor, ammo creates internal acceleration structures (BVH) that takes time. The more segments in your sphere, the longer the hiccup.
Then, the error message ‘Physics is not enabled’ happens because after clicking the play button in PG, the intervals are not cleared and the interval callback still runs. So the CB function keeps track of a half disposed scene (wihtout physics) and you get the error.
It’s the same with settimeout.
Aren’t those timers cleared when clicking the play button? Was it the same before? @Deltakosh@Evgeni_Popov
It’s the responsibility of the PG writer to remove the timeout/intervals on scene.dispose, for eg.
The PG ecosystem does not keep track of the timers/intervals you could have set.
Note it’s the same thing if you add HTML elements to the rendering area: if you don’t remove them on scene.dispose (or on any other event that would trigger when the PG is restarted) they will remain on screen at the next click on “Play”.
import * as Ammo from 'ammo.js'
const AmmoPlugin = new AmmoJSPlugin(true, Ammo)
I probably messed up trying to reproduce it in the Playground by adding a MeshImposter to a sphere. I’d swear the code in the OP worked in 4.1.0 but I can’t actually reproduce it now . Things worked and then stopped working after a yarn upgrade…
Anyway, I think the problem is solved but I’m still not entirely sure what went wrong exactly (probably a bunch of things).