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

Destroying a group with a sprite containing an animation on the onComplete signal causes a JS error. #1679

Closed
trueicecold opened this issue Mar 19, 2015 · 6 comments

Comments

@trueicecold
Copy link

Example code:

this.enemy_sprite = this.group.create(x, y, 'zombie');
this.enemy_sprite.scale.set(1);
this.enemy_sprite.scale.x = -1;
this.enemy_sprite.smoothed = false;
this.enemy_sprite.anchor.set(0.5, 0.5);

this.walk_anim = this.enemy_sprite.animations.add('walk');
this.walk_anim.onComplete.add(this.destroy, this);
this.walk_anim.play(10, false);

this.destroy = function() {
    this.group.destroy(true);
}

causes a JS error:

Uncaught TypeError: Cannot read property 'getFrame' of null phaser.js:53464 
Phaser.Animation.update phaser.js:53464 
Phaser.AnimationManager.update phaser.js:52802 
Phaser.Sprite.preUpdate phaser.js:37442 
Phaser.Group.preUpdate phaser.js:21860 
Phaser.Group.preUpdate phaser.js:21860 
Phaser.Stage.preUpdate phaser.js:20367 
Phaser.Game.updateLogic phaser.js:26737 
Phaser.Game.update phaser.js:26684 
Phaser.RequestAnimationFrame.updateRAF phaser.js:46614 
Phaser.RequestAnimationFrame.start._onLoop phaser.js:46598 

Note: delaying the "group destroy" by using setTimeout seems to fix it, but it's not a proper solution...
My guess is that the animation keeps running for a couple more frames even when the onComplete signal was sent?

Using Phaser 2.2.2

@pnstickne
Copy link
Contributor

It sprite doesn't keep running.

The problem is group.destroy triggers a destroy of the animation from within the update - but later on, in the same update, the (now invalid) _frameData.getFrame is called.

The setInterval (of any amount) delays the side-effects until later.

@pnstickne
Copy link
Contributor

There is a patch for the issue.

In the meantime the best work-about is probably to keep using setInterval(.., 0).

YMMV with destroying objects from other events.

@photonstorm
Copy link
Collaborator

Fix merged in dev.

@trueicecold
Copy link
Author

Downloaded Tarabon yesterday, the bug still occurs. But setTimeout seems to work just fine.

@pnstickne
Copy link
Contributor

@trueicecold Make sure to build locally (and not just a build pulled from git) when testing these 'latest and greatest' in dev.

If you can still reproduce it on dev, please create a minimal test case and I'll take look at it. There are several different scenarios to guard and it is very possible that one is missed. In my local tests I was able to destroy the sprite/animation/group from within the onXYZ events of the animation.

@trpzn
Copy link

trpzn commented Jun 14, 2015

Bug still active
Uncaught TypeError: Cannot read property 'preUpdate' of undefinedc.Group.preUpdate @ phaser.js:21393c.Stage.preUpdate @ phaser.js:19862c.Game.updateLogic @ phaser.js:26381c.Game.update @ phaser.js:26327c.RequestAnimationFrame.updateRAF @ phaser.js:44881c.RequestAnimationFrame.start.window.requestAnimationFrame.forceSetTimeOut._onLoop @ phaser.js:44865

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

4 participants