Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P2 Body Destroy #1077

Closed
jonathanhooker opened this issue Jul 29, 2014 · 2 comments
Closed

P2 Body Destroy #1077

jonathanhooker opened this issue Jul 29, 2014 · 2 comments

Comments

@jonathanhooker
Copy link

Calling body.destroy() on a P2 body will cause an error. The destroy function does not null the sprite's body variable and during the next sprite.postUpdate(); it will attempt to run body.postUpdate() which is where the error occurs.

You can manually set sprite.body = null; after calling the destroy function to avoid this, but it seems this should be handled by the destroy function. Here is an example on jsfiddle

http://jsfiddle.net/Rr4LB/1/

@gamedolphin
Copy link
Contributor

 destroy: function () {

        this.removeFromWorld();

        this.clearShapes();

        this._bodyCallbacks = {};
        this._bodyCallbackContext = {};
        this._groupCallbacks = {};
        this._groupCallbackContext = {};

        if (this.debugBody)
        {
            this.debugBody.destroy();
        }

        this.debugBody = null;
        this.sprite.body = null;  //THIS LINE COULD FIX THIS... 
        this.sprite = null;

    },

I don't know for sure though... cant test this right now.

photonstorm added a commit that referenced this issue Aug 28, 2014
…he parent sprite body, causing it to error in the next update (thanks @jonathanhooker #1077)
@photonstorm
Copy link
Collaborator

Fixed in dev, also happened to ArcadePhysics Body, so fixed for that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants