phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.16k stars 7.1k forks source link

Memory leak when using preFX in the same scene as a 3.8 Spine object #6856

Open Bambosh opened 4 months ago

Bambosh commented 4 months ago

Version

Description

If you assign preFX to any gameObject in a scene that also contains a 3.8 spine object, something goes wacky in the renderer and starts spewing the same instructions into this.renderer.glAttribLocationWrappers on repeat. Game performance eventually tanks, as renderer.glAttribLocationWrappers.indexOf() is run multiple times per render cycle.

Example Test Code

Click the text to trigger the bug https://codepen.io/Bambosh/pen/KKjKdxP

Additional Information

greptile-apps[bot] commented 4 months ago

For internal use only

To address the memory leak issue in Phaser 3.80.1, please check the following updates and fixes:

  1. DynamicTexture: Ensure setSize(width, height) is called for both WebGL and Canvas. This prevents width and height from being set to -1 in Canvas mode.

    DynamicTexture.setSize(width, height);
  2. DynamicTexture: Check if the glTexture bound to the current frame is stale and destroy it before binding the one from the Render Target to prevent memory leaks.

    if (this.glTextureIsStale) {
       this.destroyGLTexture();
       this.bindRenderTargetTexture();
    }

Refer to the changelog for version 3.80.1 for more details on these fixes.

References

/changelog/3.80.1/CHANGELOG-v3.80.1.md /changelog/3.80/CHANGELOG-v3.80.md

#### About Greptile This response provides a starting point for your research, not a precise solution. Help us improve! Please leave a ๐Ÿ‘ if this is helpful and ๐Ÿ‘Ž if it is irrelevant. [Ask Greptile](https://app.greptile.com/chat/github/phaserjs/phaser/master) ยท [Edit Issue Bot Settings](https://app.greptile.com/apps/github)
Scross086 commented 3 months ago

I see this with later versions of spine as well. If you use preFX and spine in the same scene, a significant memory leak begins. I'm using spine 4.1 I think

GillesVermeulen commented 1 week ago

I'd like to confirm that this is still an issue with Phaser v3.86.0 and @esotericsoftware/spine-phaser v4.2.61.

I can't use a Spine object in the same scene as an object with preFX appplied to it, without a serious memory leak.