Unload or deactivate ammo.js (engine only)

Does anyone know how to “unload” ammo.js? There’s a call to start up ammo, AmmoLib(), but is there a function that can be called to disable it? PC and ammo.js are working well in my web app but when I have to restart the app in the browser (most every time I change the code), I start getting errors from ammo and errors from the mouse-handling routines in PC. This is usually fixable with one more reload, but sometimes it takes two re-loads to stop the errors. I can live with it but I would like to fix it if there’s a way. Often the errors don’t even affect how the app behaves but it makes debugging very difficult because of the constant stream of error messages in the console.

How is the restarting of the app works in your dev environment? Does it reload the page or something different?

Yes, I’m clicking the Reload button in Chrome. It’s actually a Meteor / Vue app. Meteor is listening for changes in the files and sometimes restarts the app on it’s own. Occasionally, the “hot-code swapping" works and it doesn’t restart but does integrate the code changes. With the addition of Vue to the app, that auto-restart and hot code swapping have become less reliable.

That’s weird that reloading the browser is causing this issue with Ammo :thinking: and shouldn’t require multiple reloads.

Could you post a screenshot of the errors that you get please? There may be some clue there

I’ve discovered a workaround that has stopped some of the errors. (An Activated hook was firing during restart causing the component to try and load PC after he canvas object had already been destroyed, so … simple enough to check and see if it’s there!). Anyway, the problem is more consistent now. If the component with my PC app in it is active when I change a file and the auto-restart happens, this is what I see. Another restart kills it. This is now a very consistent pattern.

Screen Shot 2021-03-10 at 12.24.53 PM

Is the auto restart a refresh of the browser or reloading the canvas/app in the browser without refreshing?

You may need to consider destroying the pc Application before the reload?


Is there a way to provide a small producible for this?

I think you are exactly right about the need to destroy the pc app before the reload starts. Unfortunately, Meteor has no hook that lets you know when a restart occurs. The only workarounds run on the server (like listening for the socket connection to close) … even if that works, you’re still in a jam because Meteor doesn’t have a straightforward way to send a message from the server to a particular client. There are 3rd party packages that have this feature … but at this point, I’ve decided to live with it. I do hope to figure out how to reproduce this setup in a fiddle or codepen, because I am sure to have more questions like this! Thanks, as always, the help.

If you can provide a GitHub repo for a repro, we are happy to setup locally