Bug (and proposed fix): NullEngine recreates the texture for the glow layer every frame

The render() method in effectLayer.ts checks whether the current main texture size matches the desired size; it disposes and recreates it if it doesn’t. Unfortunately when running with the null engine, the size of the created texture is always zero (whatever size arguments are passed into its constructor) so it never matches the desired size and is thus recreated every time.

I’m afraid I haven’t created a repro of this outside my project (let me know if you need one), but I do have a proposed fix. Changing things such that textures return their intended size when running under the null engine seemed like quite an invasive and risky change, so my fix just changes effectLayer.ts to remember the size it asked for and check against that rather than the reported size of the texture. This is the PR: Fix bug where glow layer is recreated every frame under NullEngine by djn24 · Pull Request #16908 · BabylonJS/Babylon.js · GitHub

I have just noticed there is an _engine property. Could you check for instanceof NullEngine and if true, skip the recreation (or whatever is necessary at this point in the effectLayer)? This way you do not have to worry about storing an extra w/h.

That would have been an alternative option (though the PR’s been merged now).

One advantage with the fix as it is: When the effect layer notices a size change it notifies the size change observable. With the fix in place, it will notify the same way that the regular engine would. I’m guessing a lot of people use the NullEngine for integration tests (I certainly do!) so generally operating as similarly as possible to the regular engine is helpful.

1 Like