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

NodeJS: scene started before plugins loaded #6893

Closed
hubertgrzeskowiak opened this issue Aug 19, 2024 · 4 comments
Closed

NodeJS: scene started before plugins loaded #6893

hubertgrzeskowiak opened this issue Aug 19, 2024 · 4 comments

Comments

@hubertgrzeskowiak
Copy link

hubertgrzeskowiak commented Aug 19, 2024

Description

This is a duplicate of geckosio/phaser-on-nodejs#13, but I'm hoping that somebody on this project might have some hints on the problem.

In short, when running on NodeJS, Phaser starts the system scene and the first scene set in global config before initialising any of the plugins specified in the game config. This seems to be caused by the texture manager finishing unexpectedly early and starting the main game loop, before the game's boot event is even fired - the plugin manager is listening on that for booting.

Any idea how to debug this? I find Phaser's boot sequence events rather confusing.

  • Phaser Version: 3.70
@zekeatchan
Copy link
Collaborator

Hi @hubertgrzeskowiak. Thanks for submitting this issue. We have fixed this and pushed it to the master branch. It will be part of the next release. Do test it out and let us know if you encounter any issues.

@hubertgrzeskowiak
Copy link
Author

Thanks heaps, @zekeatchan! That's some awesome news. And who would have thought that the fix is literally a single line (I spent a few hours trying to debug this).

I will try to test it next time I've got some time, but that may take a few weeks.

@zekeatchan
Copy link
Collaborator

Cheers @hubertgrzeskowiak, glad to be of help and hope it works as expected. Feel free to add a comment or reopen this issue if this is still a problem.

@hubertgrzeskowiak
Copy link
Author

Just tested this and it still doesn't seem to work for me...

Here's a sample for reproducing:

import "@geckos.io/phaser-on-nodejs";
import Phaser from "phaser";
import BasePlugin = Phaser.Plugins.BasePlugin;
import GameConfig = Phaser.Types.Core.GameConfig;

class MyPlugin extends BasePlugin {
  foo() {
    return "bar";
  }
}

class SampleScene extends Phaser.Scene {
  myplugin: MyPlugin = this["myplugin"];

  constructor() {
    super("samplescene");
  }

  create() {
    console.log(this.myplugin.foo());
  }
}

const config: GameConfig = {
  type: Phaser.HEADLESS,
  width: 800,
  height: 600,
  plugins: {
    global: [
      { key: "MyPlugin", plugin: MyPlugin, mapping: "myplugin" }
    ]
  },
  scene: [SampleScene]
};

new Phaser.Game(config);

Remove the nodeJS import and switch render type to AUTO and it work in a browser, but on NodeJS, this gives me:

Phaser v3.88-FB (Headless | HTML5 Audio) https://phaser.io/v388
Error: Uncaught [TypeError: Cannot read properties of undefined (reading 'foo')]
at reportException (/Users/hgrzeskowiak/hugo-game/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
at innerInvokeEventListeners (/Users/hgrzeskowiak/hugo-game/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:353:9)
at invokeEventListeners (/Users/hgrzeskowiak/hugo-game/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3)
at DocumentImpl._dispatch (/Users/hgrzeskowiak/hugo-game/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:217:9)
at fireAnEvent (/Users/hgrzeskowiak/hugo-game/node_modules/jsdom/lib/jsdom/living/helpers/events.js:18:36)
at dispatchEvent (/Users/hgrzeskowiak/hugo-game/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:449:9)
at /Users/hgrzeskowiak/hugo-game/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:454:11
at new Promise ()
at onDOMContentLoad (/Users/hgrzeskowiak/hugo-game/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:452:14)
at Object.check (/Users/hgrzeskowiak/hugo-game/node_modules/jsdom/lib/jsdom/browser/resources/resource-queue.js:76:23) TypeError: Cannot read properties of undefined (reading 'foo')
at SampleScene.create (file:///Users/hgrzeskowiak/hugo-game/packages/demo-server/dist/bug-demo.js:15:35)
at SceneManager.create (/Users/hgrzeskowiak/hugo-game/node_modules/phaser/src/scene/SceneManager.js:622:26)
at SceneManager.bootScene (/Users/hgrzeskowiak/hugo-game/node_modules/phaser/src/scene/SceneManager.js:512:18)
at SceneManager.start (/Users/hgrzeskowiak/hugo-game/node_modules/phaser/src/scene/SceneManager.js:1267:14)
at SceneManager.bootQueue (/Users/hgrzeskowiak/hugo-game/node_modules/phaser/src/scene/SceneManager.js:262:18)
at EventEmitter.emit (/Users/hgrzeskowiak/hugo-game/node_modules/eventemitter3/index.js:180:35)
at Game.texturesReady (/Users/hgrzeskowiak/hugo-game/node_modules/phaser/src/core/Game.js:416:21)
at TextureManager.emit (/Users/hgrzeskowiak/hugo-game/node_modules/eventemitter3/index.js:180:35)
at TextureManager.updatePending (/Users/hgrzeskowiak/hugo-game/node_modules/phaser/src/textures/TextureManager.js:232:18)
at TextureManager.emit (/Users/hgrzeskowiak/hugo-game/node_modules/eventemitter3/index.js:182:35)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
@photonstorm @hubertgrzeskowiak @zekeatchan and others