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

Headless mode crashes if antialiasing is disabled. #6663

Closed
moufmouf opened this issue Oct 30, 2023 · 1 comment
Closed

Headless mode crashes if antialiasing is disabled. #6663

moufmouf opened this issue Oct 30, 2023 · 1 comment

Comments

@moufmouf
Copy link
Contributor

Version

  • Phaser Version: 3.60.0
  • Operating system: any
  • Browser: any

Description

Using Phaser in headless mode + disabling antialiasing causes Phaser to crash.

Example Test Code

const config = {
    type: Phaser.HEADLESS,
    parent: 'phaser-example',
    width: 800,
    height: 600,
    render: {
      pixelArt: true,
      antialias: false,
    },
    scene: [ ]
};
const game = new Phaser.Game(config);

JSFiddle: https://jsfiddle.net/6so8qry9/

Additional Information

The issue comes from the fact we try to detect if webgl is enabled in the renderer. But the renderer is null.

                setFilter: function(t) {
                    this.renderer.gl && this.renderer.setTextureFilter(this.glTexture, t),
                    this.scaleMode = t
                },

I'm not a Phaser expert, but I think the root issue is that the renderer is "null" when Headless mode is used.
It is very easy to assume in Phaser code (or in user-land code) that there will always be a renderer (the Typescript types say that the renderer is not nullable). Instead of setting the renderer to null, could it be possible to actually code a "HeadlessRenderer" object that features all the methods of a classic renderer, but that does nothing?
This approach of a "void object" is fairly common in object oriented programming. What do you think?

@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

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

No branches or pull requests

2 participants