phaser
phaser copied to clipboard
Phaser crashes if a BitmapMask is created after WebGL context is lost
Version
- Phaser Version: 3.55.2
- Operating system: Windows 10
- Browser: Chrome 97 and Firefox 96
Description
When creating a BitmapMask after a WebGL context loss, Phaser crashes with the following stacktrace.
Uncaught TypeError: Cannot set properties of null (setting 'isAlphaPremultiplied')
at WebGLRenderer.createTexture2D (phaser.js:82723:38)
at BitmapMask.createMask (phaser.js:71824:37)
at new BitmapMask (phaser.js:71786:14)
at Scene.<anonymous> (pen.js?key=pen.js-98c0ca41-c6d7-3355-35da-dc56d6850488:30:16)
at InputPlugin.emit (phaser.js:1907:35)
at InputPlugin.processUpEvents (phaser.js:187055:22)
at InputPlugin.update (phaser.js:185812:35)
at InputManager.updateInputPlugins (phaser.js:93090:47)
at InputManager.onMouseUp (phaser.js:93320:14)
at HTMLCanvasElement.onMouseUp (phaser.js:94500:25)
Example Test Code
This is a minimal reproducible example. Clicking within the canvas will force a context loss and then create a bitmap mask.
https://codepen.io/orjandh/pen/poWQWXy
Additional Information
The way createTexture2D is programmed in Phaser seems to go against what the documentation of WebGL recommends. It is recommended to not add properties to WebGL resources for seamless context loss handling.
https://www.khronos.org/webgl/wiki/HandlingContextLost#Don.E2.80.99t_put_attributes_on_WebGL_resource_objects