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

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:

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.

Which function is this?

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:


    /**
     * 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);
    },

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 but I can’t reproduce the error.

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 :woman_shrugging:t2:

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.

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…? :woman_shrugging:t2:

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