Skip to content

Commit

Permalink
Fix for issue phaserjs#917, Physics.P2.Body#addToWorld
Browse files Browse the repository at this point in the history
Fix for issue phaserjs#917: Calling reset() on Sprite with a P2 body can result in body.data.world == null.
Calling addToWorld() would previously not check the _toRemove array, which could, if the timing were right, result in a Sprite being revived but then removed from the P2 World--the result of this being the Sprite's data would be in a mixed state causing it to appear visually but not function in the world.
  • Loading branch information
jonkelling committed Jun 16, 2014
1 parent 560a44f commit dc49cfc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/physics/p2/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,18 @@ Phaser.Physics.P2.Body.prototype = {
* @method Phaser.Physics.P2.Body#addToWorld
*/
addToWorld: function () {


if (this.game.physics.p2._toRemove)
{
for (var i = 0; i < this.game.physics.p2._toRemove.length; i++)
{
if (this.game.physics.p2._toRemove[i] === this)
{
this.game.physics.p2._toRemove[i].splice(i, 1);

This comment has been minimized.

Copy link
@jonkelling

jonkelling Jun 17, 2014

Author Owner

This line is an error. It should be ..._toRemove.splice(i, 1);

}
}
}

if (this.data.world !== this.game.physics.p2.world)
{
this.game.physics.p2.addBody(this);
Expand Down

1 comment on commit dc49cfc

@jonkelling
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contains error. Replaced by 0b3f491.

Please sign in to comment.