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

RenderTexture Memory Leak #4239

Closed
sjb933 opened this issue Dec 16, 2018 · 4 comments
Closed

RenderTexture Memory Leak #4239

sjb933 opened this issue Dec 16, 2018 · 4 comments

Comments

@sjb933
Copy link
Contributor

sjb933 commented Dec 16, 2018

Version

  • Phaser Version: 3.15.1

  • Operating system: Windows 10, Mac OS

  • Browser: Verified issue on Chrome and Firefox, no other browsers tested

Description

Using RenderTexture exposes a memory leak, presumably in the TextureManager.

Example Test Code

I'm working in a more complex typescript/webpack build setup, but I've created a reduced example for reproducing the issue:

  1. Load the test in browser, take a memory snapshot.
  2. Press SPACE to recreate the scene, take another snapshot and compare.
<!DOCTYPE html>
<html>

<head>
  <script src="https://cdn.jsdelivr.net/npm/phaser@3.15.1/dist/phaser-arcade-physics.min.js"></script>
</head>

<body>

  <script>
    var MyScene = new Phaser.Class({

      Extends: Phaser.Scene,

      initialize: function MyScene(config) {
        Phaser.Scene.call(this, { ...config, key: 'MEMLEAK' })
      },

      create: function () {
        console.log("CREATE SCENE");

        // instantiation of this object creates a leak
        const rTex = this.add.renderTexture(200, 150, 400, 300).fill(0x990000);

        /** 
        * you can manually destroy this texture here and the leak is still present
        * this makes no real difference as the texture is destroyed when the scene is restarted
        */
        // rtex.destroy();

        // PRESS SPACEBAR TO RECREATE THE SCENE AND CAUSE THE LEAK - COMPARE MEMORY SNAPSHOTS TO OBSERVE BEFORE/AFTER
        this.input.keyboard.removeAllListeners();
        this.input.keyboard.on('keydown_SPACE', () => game.scene.start('MEMLEAK'));
      }

    });

    const config = {
      type: Phaser.WEBGL,
      width: 800,
      height: 600,
      input: {
        keyboard: true
      },
      backgroundColor: '#000000',
      scene: MyScene
    };

    const game = new Phaser.Game(config);

  </script>

</body>

</html>

Additional Information

Screenshots from Chrome and Firefox memory comparisons:

Chrome
image

Firefox
image

@sjb933
Copy link
Contributor Author

sjb933 commented Dec 16, 2018

I verified that this issue occurs in both CANVAS and WEBGL mode. Let me know if I can provide any additional information. I appreciate all the time and effort put into this project 🍻

@photonstorm
Copy link
Collaborator

photonstorm commented Dec 18, 2018

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.

@photonstorm
Copy link
Collaborator

Also, although it doesn't make any difference this time, please use the Scene Plugin, not the Scene Manager (game.scene) as it won't have a chance to run any other events in the current queue.

@sjb933
Copy link
Contributor Author

sjb933 commented Dec 19, 2018

Awesome, thank you for the quick support! 🍻

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