Skip to content

Error stopping a scene: cannot read property 'destroy' of undefined #5520

Closed
@schontz

Description

Version

  • Phaser Version: 3.5.1
  • Operating system: Mac and Windows
  • Browser: Chrome

Description

Shutting down a scene causes an error:

TypeError: Cannot read property 'destroy' of undefined
    at DisplayList.shutdown (phaser.js:163448)
    at EventEmitter.emit (phaser.js:1928)
    at Systems.shutdown (phaser.js:47907)
    at SceneManager.stop (phaser.js:99258)

The error in DisplayList is here:
https://github.com/photonstorm/phaser/blob/master/src/gameobjects/DisplayList.js#L234

I believe the issue is that some of the objects being destroyed are in turn destroying some sub-objects, which would be on this.list, thus making the list shorter.

This could be fixed like so:

while(list.length) {
  list[0].destroy(true);
}

That would be unaffected by changes to the list along the way.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions