-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Fixes null @ currentBatch due flush() calls @ LightPipeline.js #6822
Conversation
The next test scenario might reveal an exception/crash due null values at currentBatch property of LightPipeline: 1) Mesh gameobject -> .setPipeline('Light2D') 2) Applying a rotation to the mesh 2) Crash flow: MeshWebGLRenderer -> setGameObject -> setNormalMapRotation -> flush Rationale: setGameObject @ MeshWebGLRenderer invoking a flush @ setNormalMapRotation and making currentBatch=null. The crash happens @ MeshWebGLRenderer once reading a property on currentBatch (null).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
- Fixed bug in
src/renderer/webgl/pipelines/LightPipeline.js
wherecurrentBatch
could be null afterflush()
call - Ensured new batch creation if
currentBatch
is null to prevent crashes - Watch for potential side effects in
setGameObject
andsetNormalMapRotation
methods
1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
@urueda I am not able to reproduce the bug mentioned. Here is a link to the test code: It would be great if you could provide a link that demonstrates the bug you mentioned so that we can investigate further. Thanks. |
@zekeatchan I suggest:
For the bug to reveal you would need a batch flush to happen when rendering the mesh. |
We don't test against 3.70, as 3.80 is the current version. The Mesh we tested with has 10,136 faces, which is about the limit of the number of faces a Mesh should have in Phaser 3. The batch size is 4096 by default. I forced it down to 1024 in the config it still doesn't cause a crash, even though you can clearly see it flushing multiple times during the single draw in Spector.gl. As it stands, unless you can provide us with a reproducible test case against v3.80 then we can't move ahead with this issue. |
Please, find next a test code revealing the bug: https://phaser.io/sandbox/xv7EdA2P |
The sandbox is what should have been provided at the very start, really. You don't need to call class Example extends Phaser.Scene
{
constructor ()
{
super();
}
preload ()
{
this.load.setPath('https://labs.phaser.io/assets/obj/racing/');
this.load.obj('roadStart', 'roadStartPositions.obj', 'roadStartPositions.mtl');
}
create ()
{
this.add.rectangle(50, 50, 50, 50, 0xff0000, 0.25).setPipeline('Light2D');
const track = this.add.mesh(400, 300);
track.setPipeline('Light2D');
const rot90 = Phaser.Math.DegToRad(90);
const rot180 = Phaser.Math.DegToRad(180);
track.addVerticesFromObj('roadStart', 1, 0, 0, 0, rot90, rot180);
track.setRotation(Math.random());
}
}
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#0a440a',
parent: 'phaser-example',
scene: Example
};
let game = new Phaser.Game(config);
Comment out the rectangle before it, and it doesn't crash. Remove the Light2D pipeline from the rectangle and it doesn't crash. Add a sprite or text or anything not using Light2D before the Mesh, and it doesn't crash. The combination is very specific: Something using Light2D immediately before a Mesh that uses Light2D, and you have to then immediately invalidate the Mesh to trip the bug. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
- Fixes null
currentBatch
afterflush()
insrc/renderer/webgl/pipelines/LightPipeline.js
- Adds check for
currentBatch
null and creates new batch if necessary - Prevents crashes in
setGameObject
andsetNormalMapRotation
methods
1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
Thanks for opening this issue, and for submitting a PR to fix it. We have soft-merged your PR into the |
This PR: Fixes a bug
Test scenario:
The test might reveal an exception/crash due null values at currentBatch property of LightPipeline.
Crash flow: MeshWebGLRenderer -> setGameObject -> setNormalMapRotation -> flush
Rationale: setGameObject @ MeshWebGLRenderer invoking a flush @ setNormalMapRotation and making currentBatch=null.
The crash happens @ MeshWebGLRenderer once reading a property on currentBatch (null).