kripken / ammo.js

Direct port of the Bullet physics engine to JavaScript using Emscripten

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

btCollisionWorld.removeCollisionObject does not work

kaphula opened this issue · comments

Hello,

Can anyone confirm that btCollisionWorld.removeCollisionObject is working properly in ammo.js? When I call this method my simulation breaks. Further more, reading the source code of bullet reveals that many bullet functions call btAssert(...) internally. I could not figure out what does that internal assert do if it gets executed. Does it crash bullet or just exit the current function that is being executed? Is it possible to get errors or warnings generated by bullet to the javascript side?

commented

Work fine, here is my code.
Depending how Bullet calculate your collision, some infos stay in memory.
The cleanest answer I found was to delete the RigidBody reference too (not mandatory, but avoid memory leak)

//set world
const world = new AmmoLib.btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);

//main code here....

//remove collisions and any references of an object
world.removeCollisionObject(body);
world.removeRigidBody (body);
AmmoLib.destroy(body);

Thank you, yeah I accidentally misunderstood the functionality of btCollisionWorld.removeCollisionObject. I thought removeCollisionObject and addCollisionObject were functions for setting an already added object's collision filter values separately. But it seems there's no way to dynamically alter the collision filter settings (group / mask) once an object has been added to a physics world.