Skip to content

Commit 2ecb0c7

Browse files
committed
P2.removeBody will check if the body is part of the world before removing, this avoids a TypeError from the p2 layer.
1 parent f32dce8 commit 2ecb0c7

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Updated:
7171

7272
* Updated Device.isConsoleOpen as it no longer works in Chrome. Revised code and documentation accordingly (fix #593)
7373
* Removed State.destroy empty method and replaced with State.shutdown, as that is what the StateManager expects (fix #586)
74+
* P2.removeBody will check if the body is part of the world before removing, this avoids a TypeError from the p2 layer.
7475

7576

7677
TODO:

src/physics/p2/World.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,17 +711,20 @@ Phaser.Physics.P2.prototype = {
711711
},
712712

713713
/**
714-
* Removes a body from the world.
714+
* Removes a body from the world. This will silently fail if the body wasn't part of the world to begin with.
715715
*
716716
* @method Phaser.Physics.P2#removeBody
717717
* @param {Phaser.Physics.P2.Body} body - The Body to remove from the World.
718718
* @return {Phaser.Physics.P2.Body} The Body that was removed.
719719
*/
720720
removeBody: function (body) {
721721

722-
this.world.removeBody(body.data);
722+
if (body.data.world == this.world)
723+
{
724+
this.world.removeBody(body.data);
723725

724-
this.onBodyRemoved.dispatch(body);
726+
this.onBodyRemoved.dispatch(body);
727+
}
725728

726729
return body;
727730

0 commit comments

Comments
 (0)