Gamua / Starling-Framework

The Cross Platform Game Engine
http://www.starling-framework.org
Other
2.87k stars 826 forks source link

GPU memory leak #726

Closed chadrem closed 9 years ago

chadrem commented 9 years ago

I believe I am encountering a GPU memory leak that the same or similar to the one in issue #707. I am using the latest Starling and latest Feathers as of Wed Jun 10 11:59:23 EDT 2015 with the latest Adobe Air 18 beta SDK.

Starling latest commit: 68aa0813dc8f822ec07b83401c65f627aecc17d2 Feathers latest commit: 1a8e67c31d25d88b29d10b1b888bba8055ca967c

My code does the following...

  1. Creates a Image using a texture from Starling's asset manager.
  2. Applies a BlurFilter to the image.
  3. Adds the image as a child of a sprite.
  4. Flatten's the sprite and it's child.
  5. On a timer it removes the sprite, disposes it, and recreates it along with the child. If a filter is used, the app leaks GPU memory. No filter, no leak.

After a few hundred iterations of the above, Scout reports GPU memory in the mid 500MB range and the app crashes. No crash (or memory leak) occurs if I comment out the line where I apply the filter (image.filter = new BlueFilter...).

The below code demonstrates the leak.

  private var _count:int = 0;
  private var _image:Image;
  private var _container:Sprite;

  // Call the 'run' method to demonstrate the leak.
  // Comment out the below filter line to make the leak go away.
  public function run():void {
    var timer:Timer = new Timer(500, int.MAX_VALUE);
    timer.addEventListener(TimerEvent.TIMER, execute);
    timer.start();
  }

  private function execute(event:TimerEvent):void {
    // Remove and dispose container if it exists.
    if (_container)
      removeChild(_container, true);

    // Create new container.
    _container = new Sprite();
    addChild(_container);

    // Create new image.
    var texture:Texture = AssetManager.instance.getTexture('main_menu_scene/border');
    _image = new Image(texture);

    // Filter for the image.
    var filter:BlurFilter = new BlurFilter(1.5, 1.5, 2);
    _image.filter = filter; // Comment out this line and the memory leak goes away.

    // Attach the image to the container.
    _container.addChild(_image);

    // Flatten container and it's children.
    _container.flatten();

    // Monitor loop count.
    trace(_count++);
  }
PrimaryFeather commented 9 years ago

Thanks for the report, I'll look into it as soon as possible! Sorry for not answering in the other thread, I was on a vacation and am still trying to catch up with everything I missed. ;-)

chadrem commented 9 years ago

@PrimaryFeather No worries we all need to take more vacations, not less! Please let me know if there is anything else I can do to help and thank you for all of your hard work on this project.

PrimaryFeather commented 9 years ago

Okay, I can reproduce it and I understand the problem. It's a little tricky to solve, though ... :wink: I'll get back to you as soon as I've a smart idea.

chadrem commented 9 years ago

@PrimaryFeather glad to hear you reproduced it and sorry to hear it's a tricky one... please let me know if I can do anything to help.

PrimaryFeather commented 9 years ago

That should do it! :smile: Please try out if that fixes the problem in your main application, as well.

Thanks again for making me aware of this problem! I'm sure that bug let to nasty / hard to locate memory problems in the past. Good that it's gone!

chadrem commented 9 years ago

@PrimaryFeather A giant thank you! I have confirmed with Scout that the problem is fixed in our app.

PrimaryFeather commented 9 years ago

Ah, wonderful! I'm glad to hear that! :smile: Thanks for the update!