Scene Shutdown - Error 'destroy' of undefined

Hi,

i’m getting some strange errors sometimes if i shutdown my scene after game finished…

TypeError: Cannot read property 'destroy' of undefined

It is thrown at line 41176 of the “phaser.min.js” (on pretty print)

shutdown: function() {
                for (var t = this.list, e = t.length; e--; )
                    t[e].destroy(!0);
                t.length = 0,
                this.events.off(a.SHUTDOWN, this.shutdown, this)
            },

While debugging this, i see:
“this.list” has a length of 47, “e” is set to “47” and inside the for-loop it must crash each time because u cant access a item in array out of range :slight_smile:
e should be 46 inside loop, but it isnt…

what am i doing wrong?

Why i get this error sometimes, sometimes not… :confused:

I have many objects in my game that are spawned randomly and also have a lifespan and getting destroyed after some times… So. Maybe the “shutdown” is colliding with this “lifespan” destroys?

:slight_smile:

You’re stopping the scene when?

Which Phaser version?

I’m stopping the scene with:

this.scene.stop("game");

This is called in a second scene (“gui”) with is still running.

i think i found the problem…
in one of my object-classes i have a overwrite for the “destroy” function.
inside this function, i check if a “child” is still present and try to destroy this, too.
mayby my “child-destruction” is fired before the scene can destroy the child on its own…

i managed it to check this with:

if( this.scene && this.scene.scene.isActive() ){
            if( this.hp && this.hp.active ) this.hp.destroy();

:slight_smile:

1 Like