Browse Source

Correctly disposing joints

Raanan Weber 9 years ago
parent
commit
ef3d533022

+ 2 - 2
src/Physics/Plugins/babylon.cannonJSPlugin.ts

@@ -205,8 +205,8 @@
             }
             }
         }
         }
 
 
-        public removeJoint(joint: PhysicsImpostorJoint) {
-            //TODO
+        public removeJoint(impostorJoint: PhysicsImpostorJoint) {
+            this.world.remove(impostorJoint.joint);
         }
         }
 
 
         private _addMaterial(name: string, friction: number, restitution: number) {
         private _addMaterial(name: string, friction: number, restitution: number) {

+ 4 - 0
src/Physics/babylon.physicsImpostor.ts

@@ -391,6 +391,10 @@ module BABYLON {
         }
         }
 
 
         public dispose(/*disposeChildren: boolean = true*/) {
         public dispose(/*disposeChildren: boolean = true*/) {
+            this._joints.forEach((j) => {
+                this._physicsEngine.removeJoint(this, j.otherImpostor, j.joint);
+            })
+            //dispose the physics body
             this.physicsBody = null;
             this.physicsBody = null;
             if (this.parent) {
             if (this.parent) {
                 this.parent.forceUpdate();
                 this.parent.forceUpdate();