engine icon indicating copy to clipboard operation
engine copied to clipboard

Physics + Collisions not functioning after destroying and reloading

Open MAG-AdrianMeredith opened this issue 3 years ago • 6 comments

Description

In my engine only application we may create and destroy instances as we switch between different experiences. However on entering a second time all rigidbodies and collisions no longer function and appear to be stuck at 0,0 or missing entirely. This is despite calling app.destroy() and ensuring all local data is correctly cleaned up.

Upon further investigation I have discovered it is due to the following properties being created in "module scope". This means they PERSIST between different apps even when destroyed! I would very much appreciate it if you guys could review all module scope properties as its potentially very dangerous.

on first load: working

on second load: broken

I have done the following workaround to fix the bug temporarily

image

I believe it goes wrong due to the following functions not resetting correctly (theres a few of them)?

image

I haven't been able to get a simple example together that shows the issue but hopefully my explanation above is enough to formulate a correct fix.

MAG-AdrianMeredith avatar Apr 28 '22 10:04 MAG-AdrianMeredith

@willeastcott Any ideas on this one?

yaustar avatar Apr 28 '22 11:04 yaustar

maybe it would be enough to change this line in rigid-body/component.js ?

if (typeof Ammo !== 'undefined' && !ammoTransform) { to if (typeof Ammo !== 'undefined') {

mvaligursky avatar Apr 28 '22 11:04 mvaligursky

Sounds reasonable to me @mvaligursky

willeastcott avatar Apr 28 '22 13:04 willeastcott

I might be late here for a comment, but if we overwrite a scoped varibale here with a new object instance of Ammo, wouldn't the old instance remain in Wasm? Those would need to be Ammo.destroy'ed somewhere.

LeXXik avatar Jun 16 '22 13:06 LeXXik

It's true @LeXXik - I guess I converted a real issue into a small issue .. but it'd be nice to eventually fix it too. I'll leave the ticket opened.

mvaligursky avatar Jun 16 '22 15:06 mvaligursky