File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
7677TODO:
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments