# Trying to destroy() a game instance, but get displayList is null error

**URL:** <https://phaser.discourse.group/t/trying-to-destroy-a-game-instance-but-get-displaylist-is-null-error/10144>\
**Category:** Phaser 3\
**Created:** [August 22, 2021, 4:27pm UTC](https://phaser.discourse.group/t/trying-to-destroy-a-game-instance-but-get-displaylist-is-null-error/10144 "2021-08-22T16:27:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![indextwo](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/indextwo/32/3971_2.png) [@indextwo](https://phaser.discourse.group/u/indextwo)\
**Post date:** [August 22, 2021, 4:27pm UTC](https://phaser.discourse.group/t/trying-to-destroy-a-game-instance-but-get-displaylist-is-null-error/10144/1 "2021-08-22T16:27:53Z")

</div>

Pretty much as the subject line says: I’ve tried many, many (similar) ways of destroying an entire game instance, but no matter what I try I get `Uncaught TypeError: displayList is null`

My game is set up with multiple managed scenes; so there’s a BootScene, then a PreloaderScene, then a GameScene, then a RoomScene. Initially I thought it mattered what scene I ran the command from, but it doesn’t seem to - I always get the error above.

I’ve tried variations of `GameScene.sys.game.destroy([true/false]);` & `GameScene.sys.game.runDestroy()`, but no joy. I’m not sure if there’s some other kind of tidying up I need to do first?

I’m running Phaser 3.5.4 - here’s the full debug error:

```javascript
Uncaught TypeError: displayList is null
    addToDisplayList http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:3728
    removeHandler http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:50998
    RemoveBetween http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:167555
    removeAll http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:51412
    preDestroy http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:51861
    destroy http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:3859
    shutdown http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:166333
    destroy http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:166351
    emit http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:1927
    destroy http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:48962
    destroy http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:100779
    runDestroy http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:162413
    step http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:162199
    step http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:88795
    step http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:89042
    step http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:89044

```

That last line (`89044`) is repeated several times.

All I’m aiming for is to completely unload the game from the browser (as it’s been completed and I want to show some stats in HTML), so if there’s another route, I’ll totally take it.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [August 23, 2021, 3:08pm UTC](https://phaser.discourse.group/t/trying-to-destroy-a-game-instance-but-get-displaylist-is-null-error/10144/2 "2021-08-23T15:08:08Z")

</div>

> [@indextwo](#):
>
> `shutdown http://cdn.jsdelivr.net/npm/phaser@3.54.0/dist/phaser.js:166333`

Which function is this?

---

<div class="post-metadata">

**Author:** ![indextwo](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/indextwo/32/3971_2.png) [@indextwo](https://phaser.discourse.group/u/indextwo)\
**Post date:** [August 23, 2021, 3:38pm UTC](https://phaser.discourse.group/t/trying-to-destroy-a-game-instance-but-get-displaylist-is-null-error/10144/3 "2021-08-23T15:38:13Z")

</div>

As in, what function did I run that resulted in that? That shows up in whatever `destroy()` I try, e.g. `GameScene.sys.game.destroy(false);`. The functions itself is in the Phaser core:

```javascript

    /**
     * The Scene that owns this plugin is shutting down.
     * We need to kill and reset all internal properties as well as stop listening to Scene events.
     *
     * @method Phaser.GameObjects.GameObjectFactory#shutdown
     * @private
     * @since 3.0.0
     */
    shutdown: function ()
    {
        this.events.off(SceneEvents.SHUTDOWN, this.shutdown, this);
    },

```

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [August 23, 2021, 3:49pm UTC](https://phaser.discourse.group/t/trying-to-destroy-a-game-instance-but-get-displaylist-is-null-error/10144/4 "2021-08-23T15:49:09Z")

</div>

You can try with Phaser v3.55.2.

I’ve added `this.game.destroy()` to [game%20objects/container/add%20sprite%20to%20container.js&v=3.54.0](https://labs.phaser.io/view.html?src=src/game%20objects/container/add%20sprite%20to%20container.js&v=3.54.0) but I can’t reproduce the error.

---

<div class="post-metadata">

**Author:** ![indextwo](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/indextwo/32/3971_2.png) [@indextwo](https://phaser.discourse.group/u/indextwo)\
**Post date:** [August 23, 2021, 6:42pm UTC](https://phaser.discourse.group/t/trying-to-destroy-a-game-instance-but-get-displaylist-is-null-error/10144/5 "2021-08-23T18:42:20Z")

</div>

I had the same thought earlier - just tried it with 3.55.2 and the exact same result.

There’s a _lot_ of code, and it’s a commercial development so I can’t share the source here; but it does make use of plenty of scenes, prefabs sprite atlases & audio sprites. All I can think is that maybe there’s something in that that’s somehow screwing up the logic.

The only other thing that came to mind is that when debugging the various game objects, I realised that I’m using this call:

`GameScene.sys.game.destroy(true);`

…however there’s no `displayList` under `GameScene.sys.game`; but there _is_ one under just `GameScene.sys`. I don’t know if that’s an issue or not (for example, the root `game` object does’t have a `displayList` object either, but running `game.destroy()` from the console on that demo you posted results in the game freezing, so I’m guessing that’s not the issue?)

_However_, because I’ve got several scenes that are all stacked (BootScene, Preloader, Game, Level1, etc.), I find I have to destroy them all individually, and if I get to the scene where things are showing, e.g. `FirstLevelScene.sys.game.destroy()`, then it errors out as before.

It’s all under a globally-accessible `game` var, but running a straight `game.destroy()` from the console again results in the exact same error above 🤷🏻‍♀️

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [August 23, 2021, 7:03pm UTC](https://phaser.discourse.group/t/trying-to-destroy-a-game-instance-but-get-displaylist-is-null-error/10144/6 "2021-08-23T19:03:49Z")

</div>

`game.destroy()` will also destroy all the scenes, so there’s no need to do that separately.

From the stack trace it looks like a container and its children are being destroyed after the scene is, which is weird.

---

<div class="post-metadata">

**Author:** ![indextwo](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/indextwo/32/3971_2.png) [@indextwo](https://phaser.discourse.group/u/indextwo)\
**Post date:** [August 23, 2021, 7:14pm UTC](https://phaser.discourse.group/t/trying-to-destroy-a-game-instance-but-get-displaylist-is-null-error/10144/7 "2021-08-23T19:14:44Z")

</div>

Yeah, that’s what I figured (in both instances) - the only reason I started drilling down was to try to isolate it. But yeah, I was wondering if I was hitting some edge case. For example I have emitters running, so whether it’s trying to do a cleanup of the scene to catch any stragglers, but by the time that comes around the scene is gone…? 🤷🏻‍♀️

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [August 23, 2021, 11:40pm UTC](https://phaser.discourse.group/t/trying-to-destroy-a-game-instance-but-get-displaylist-is-null-error/10144/8 "2021-08-23T23:40:17Z")

</div>

> [@indextwo](#):
>
> if I get to the scene where things are showing, e.g. `FirstLevelScene.sys.game.destroy()` , then it errors out as before.

And what happens if you do only `this.scene.remove()` in that scene?
