Return to Starling Playback Library

Crowded memory by GAF

Questions related to Starling playback library should be asked here.

Crowded memory by GAF

Postby dvrbear » January 15th, 2015, 5:55 am

After few restarts level - debuger gives Error #3691: Resource limit for this resource type exceeded.

I gues it happens because i have to many GAF RE-converting and all of them adds in new memory space.

How can i once convers fo example "Hero.zip" in memory - for a lot of times use it without NEW convertation?

Can i create same "new GAFMovieClip" after dispose without new convertation?
User avatar
dvrbear
 
Posts: 26
Joined: October 20th, 2014, 1:42 am

Re: Crowded memory by GAF

Postby Sergei Sorokin » January 15th, 2015, 7:09 am

Hi,
please post code with GAFMovieClip convertation and it's destroying. Right now I can suggest you to use GAFTimeline for creating new GAFMovieClips from it. Keep reference for timeline somewhere in your code and don't load zip with GAF every time you need to create same animation.
User avatar
Sergei Sorokin
 
Posts: 39
Joined: December 18th, 2013, 11:46 am

Re: Crowded memory by GAF

Postby dvrbear » January 16th, 2015, 12:22 am

class ConvertGAF
Code: Select all
package com.universal {
import com.assets.EmbededIntroAssets;
import com.catalystapps.gaf.core.ZipToGAFAssetConverter;
import com.catalystapps.gaf.data.GAFTimeline;
import com.catalystapps.gaf.display.GAFMovieClip;
import com.game.GameVar;
import flash.utils.ByteArray;
import flash.events.Event;
import starling.display.Sprite;

public class ConvertGAF {

    private var mc:GAFMovieClip;
    private var canConvert:Boolean = true;
    public var converList:Array = [];

    public function ConvertGAF() {
    }

    public function convert(TargetMC:Sprite, ClassName:String, getFunction:Function=null, getFrame:String="1"):void {
        converList[converList.length] = [TargetMC, ClassName, getFunction, getFrame];
        GameVar.gafConvNum++;
        tryToConvert();
    }

    private function tryToConvert():void{
        if(canConvert) {
            canConvert = false;
            var gaf:ByteArray = new EmbededIntroAssets[converList[0][1]] as ByteArray;
            var converter:ZipToGAFAssetConverter = new ZipToGAFAssetConverter();
            converter.addEventListener(Event.COMPLETE, this.onConverted);
            converter.convert(gaf);
        }
    }

    private function onConverted(event: Event): void
    {
        GameVar.gafConvNum--;
        var timeline: GAFTimeline = (event.target as ZipToGAFAssetConverter).gafTimeline;
        mc = new GAFMovieClip(timeline);
        converList[0][0].addChild(mc);
        converList[0][2](mc, converList[0][3]);
        converList.shift();
        canConvert = true;
        if(converList.length>0) {
            tryToConvert();
        }
    }
}
}
User avatar
dvrbear
 
Posts: 26
Joined: October 20th, 2014, 1:42 am

Re: Crowded memory by GAF

Postby dvrbear » January 16th, 2015, 12:27 am

Code: Select all
[Embed(source="/../assets/anim/dvr_icons1.zip", mimeType="application/octet-stream")]
        public static const GAF_ParamsBox:Class;


Code: Select all
h_ico = new IconImage("GAF_ParamsBox", "UIicon_life_hold");


class IconImage
Code: Select all
package com.universal {
import com.catalystapps.gaf.display.GAFMovieClip;
import com.game.GameVar;
import starling.display.Sprite;

public class IconImage extends Sprite{

    public var mc:GAFMovieClip;
    private var animControl:AnimControl;
    private var _startFrame:String;
    public var converted:Boolean = false;

    public function IconImage(newName:String, startFrame:String="1") {
        _startFrame = startFrame;
        GameVar.GAFer.convert(this, newName, onConvert, _startFrame);
    }
    public function onConvert(newMC:GAFMovieClip, newStart:String):void{
        mc = newMC;
        animControl = new AnimControl(mc, false, _startFrame);
        mc.gotoAndPlay(newStart);
        converted = true;
    }

    public function setNewSequence(newSequence:String):void{
        mc.setSequence(newSequence);
        animControl.startFrame = newSequence;
    }

    override public function dispose():void{

        if(mc){ mc.removeFromParent(true); mc = null; }
        if(animControl){ animControl.dispose(); animControl = null; }
        super.dispose();
    }

}
}
User avatar
dvrbear
 
Posts: 26
Joined: October 20th, 2014, 1:42 am

Re: Crowded memory by GAF

Postby dvrbear » January 16th, 2015, 3:26 am

I have Tested on one Scene many GAFMovieClips, dispose them and create them anew.
After few times debuger gives an error.
It seems - textures remain in memory after dispose and convertor add new textures in memory by new converting.

Your suggestion about saving somewhere "timeline" - i fink it will be the best solution.
I'll try to perform it.
Thank you!
User avatar
dvrbear
 
Posts: 26
Joined: October 20th, 2014, 1:42 am

Re: Crowded memory by GAF

Postby dvrbear » January 17th, 2015, 2:23 am

Maybe for someone it will be usefull:

Code: Select all
[Embed(source="/../assets/anim/frog_06.zip", mimeType="application/octet-stream")]
        public static const CharFrog:Class;

        [Embed(source="/../assets/anim/shark_6.zip", mimeType="application/octet-stream")]
        public static const CharShark:Class;


Code: Select all
var mc:GAFMovieClip = GAFCollertor.getMc(charName);


Code: Select all
package com.universal {

import com.assets.EmbededIntroAssets;
import com.catalystapps.gaf.core.ZipToGAFAssetConverter;
import com.catalystapps.gaf.data.GAFTimeline;
import com.catalystapps.gaf.display.GAFMovieClip;
import com.game.GameVar;
import flash.utils.ByteArray;
import flash.events.Event;

public class GAFCollertor {

    /////////////////////////      VARIABLES
    ////////////////////////////////////////////////////

    public static var gafAnimNames:Array  = [
        "CharFrog",
        "CharShark",
        "GAF_ParamsBox",
        "GAF_Lines",
        "GAF_Pow",
        "GAF_Bubbles",
        "GAF_Iron",
        "GAF_Rocket"];

    public static var gafTimelines:Array  = [];

    public static var converList:Array = [];
    public static var canConvert:Boolean = true;
    public static var allConverted:Boolean = false;
    public static var firstConvert:Boolean = true;


    /////////////////////////      FUNCTIONS
    ////////////////////////////////////////////////////

    // convertation

    public static function autoconvert():void{
        if(firstConvert) {
            firstConvert = false;
            for (var i:int = 0; i < gafAnimNames.length; i++) {
                convert(gafAnimNames[i], i);
            }
        }
    }

    public static function convert(nName:String, nPos:int):void {
        converList[converList.length] = [nName, nPos];
        GameVar.gafConvNum++;
        tryToConvert();
    }

    private static function tryToConvert():void{
        if(canConvert) {
            canConvert = false;
            var gaf:ByteArray = new EmbededIntroAssets[converList[0][0]] as ByteArray;
            var converter:ZipToGAFAssetConverter = new ZipToGAFAssetConverter();
            converter.addEventListener(Event.COMPLETE, onConverted);
            converter.convert(gaf);
        }
    }

    private static function onConverted(event: Event): void
    {
        GameVar.gafConvNum--;
        var timeline:GAFTimeline = (event.target as ZipToGAFAssetConverter).gafTimeline;
        gafTimelines[converList[0][1]] = timeline;

        converList.shift();
        canConvert = true;
        if(converList.length>0) {
            tryToConvert();
        }
        else{
            allConverted = true;
        }
    }

    // get timeline

    public static function getMc(nName:String):GAFMovieClip{
        var mc:GAFMovieClip = new GAFMovieClip(gafTimelines[gafAnimNames.lastIndexOf(nName)]);
        return mc;

    }

}
}
User avatar
dvrbear
 
Posts: 26
Joined: October 20th, 2014, 1:42 am

Return to Starling Playback Library

Who is online

Users browsing this forum: No registered users and 2 guests