Skip to content

Changing states with box2d enabled causes crash #1884

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

Closed
tom2strobl opened this issue Jul 1, 2015 · 8 comments
Closed

Changing states with box2d enabled causes crash #1884

tom2strobl opened this issue Jul 1, 2015 · 8 comments

Comments

@tom2strobl
Copy link

See http://www.html5gamedevs.com/topic/13753-changing-states-with-box2d-causes-crash/

When calling game.physics.startSystem(Phaser.Physics.BOX2D); and changing the state afterwards it crashes. Stack Tracing paths to this.world.GetGravity().Clone(); in World.js – it seems GetGravity() is not returning something and therefore crashing the following Clone() with .Clone is not a function.

Any ideas/hacks/workarounds?

@photonstorm
Copy link
Collaborator

Which version of the plugin is this testing with? because this bug was fixed some months ago now and a new zip file was sent to all customers at the time.

@tom2strobl
Copy link
Author

Bought it yesterday (to the email weare@wild.as) and downloaded the link from the Paddle email I don't know how else to get to the codebase to be honest – where can I find it? package.json says it's 1.0.1

@photonstorm
Copy link
Collaborator

That is the current one, and state swapping definitely works in it. Here is a test case to try it with (the assets can be found in the examples repo if you need them)

var MyGame = {};

MyGame.StateA = function (game) {

    this.sprite;
    this.cursors;

};

MyGame.StateA.prototype = {

    preload: function () {

        this.load.image('atari', 'assets/sprites/atari130xe.png');
        this.load.image('mushroom', 'assets/sprites/mushroom.png');

    },

    create: function () {

        this.physics.startSystem(Phaser.Physics.BOX2D);

        this.sprite = this.add.sprite(200, 200, 'atari');
        this.physics.box2d.enable(this.sprite);

        this.cursors = this.input.keyboard.createCursorKeys();

        this.input.onDown.add(this.changeState, this);

    },

    update: function () {

        this.sprite.body.setZeroVelocity();

        if (this.cursors.left.isDown)
        {
            this.sprite.body.moveLeft(400);
        }
        else if (this.cursors.right.isDown)
        {
            this.sprite.body.moveRight(400);
        }

        if (this.cursors.up.isDown)
        {
            this.sprite.body.moveUp(400);
        }
        else if (this.cursors.down.isDown)
        {
            this.sprite.body.moveDown(400);
        }

    },

    changeState: function () {

        this.state.start('StateB');

    }

};

MyGame.StateB = function (game) {

    this.sprite;
    this.cursors;

};

MyGame.StateB.prototype = {

    create: function () {

        this.sprite = this.add.sprite(200, 200, 'mushroom');
        this.physics.box2d.enable(this.sprite);
        this.sprite.body.fixedRotation = true;

        this.cursors = this.input.keyboard.createCursorKeys();

    },

    update: function () {

        this.sprite.body.setZeroVelocity();

        if (this.cursors.left.isDown)
        {
            this.sprite.body.moveLeft(400);
        }
        else if (this.cursors.right.isDown)
        {
            this.sprite.body.moveRight(400);
        }

        if (this.cursors.up.isDown)
        {
            this.sprite.body.moveUp(400);
        }
        else if (this.cursors.down.isDown)
        {
            this.sprite.body.moveDown(400);
        }

    }

};

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example');

game.state.add('StateA', MyGame.StateA);
game.state.add('StateB', MyGame.StateB);

game.state.start('StateA');

@tom2strobl
Copy link
Author

Turns out I copied the box2d-plugin-full.min.js from the examples/js folder which was the old version (compiled in march), the box2d-plugin-full.min.js from the regular dist folder is the newer version (compiled in may) - swapping them fixed it. Thank you so much and keep it up!

@photonstorm
Copy link
Collaborator

Ahh thanks for the heads-up! I will make sure that is replaced with the next release.

@tom2strobl
Copy link
Author

Sorry for posting on a closed issue, but I want to take the opportunity to just say thank you for the endless work on this Framework, on the first glance I threw in a Vector library just to see that every Vector method you'd need is already in there, then I threw in a Random generation library, well, just to see that everything you'd need is already in there. Then before throwing in an Array-Utility library I looked into the docs – well it's already f***ing in there!

If there's another opportunity to throw money in your direction I won't hesitate.

@clark-stevenson
Copy link
Contributor

I also want to repeat that.

Everytime I go to use something, it is magically there, and has always been there.... I just had not found it yet. It has been 18 months where I have been with Phaser in some capacity and I continue to find things which are just awesome!

👍

@photonstorm
Copy link
Collaborator

Thanks guys :)

Now I'm back at work properly I'll be wrapping up Phaser 2.4 and then (finally) releasing the Advanced Particles Plugin - which I'm sure everyone will love :)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants