Bladeren bron

Merge pull request #1111 from RaananW/fix-physics-dispose

Fixing the dispose error when no physics engine was defined
David Catuhe 9 jaren geleden
bovenliggende
commit
b8e9f25436
1 gewijzigde bestanden met toevoegingen van 7 en 2 verwijderingen
  1. 7 2
      src/Physics/babylon.physicsImpostor.ts

+ 7 - 2
src/Physics/babylon.physicsImpostor.ts

@@ -328,7 +328,7 @@ module BABYLON {
 
 
         //event and body object due to cannon's event-based architecture.
         //event and body object due to cannon's event-based architecture.
         public onCollide = (e: { body: any }) => {
         public onCollide = (e: { body: any }) => {
-            if(!this._onPhysicsCollideCallbacks.length) return;
+            if (!this._onPhysicsCollideCallbacks.length) return;
             var otherImpostor = this._physicsEngine.getImpostorWithPhysicsBody(e.body);
             var otherImpostor = this._physicsEngine.getImpostorWithPhysicsBody(e.body);
             if (otherImpostor) {
             if (otherImpostor) {
                 this._onPhysicsCollideCallbacks.filter((obj) => {
                 this._onPhysicsCollideCallbacks.filter((obj) => {
@@ -392,11 +392,16 @@ module BABYLON {
         }
         }
 
 
         public dispose(/*disposeChildren: boolean = true*/) {
         public dispose(/*disposeChildren: boolean = true*/) {
+            //no dispose if no physics engine is available.
+            if (!this._physicsEngine) {
+                return;
+            }
+
             this._joints.forEach((j) => {
             this._joints.forEach((j) => {
                 this._physicsEngine.removeJoint(this, j.otherImpostor, j.joint);
                 this._physicsEngine.removeJoint(this, j.otherImpostor, j.joint);
             })
             })
             //dispose the physics body
             //dispose the physics body
-            this._physicsEngine.removeImpostor(this); 
+            this._physicsEngine.removeImpostor(this);
             if (this.parent) {
             if (this.parent) {
                 this.parent.forceUpdate();
                 this.parent.forceUpdate();
             } else {
             } else {