rainyt / openfl-spine

Supports Spine renderer versions 3.8 to 4.2 on OpenFL
MIT License
18 stars 6 forks source link

Duplicate SkeletonAnimation #7

Closed CrazyFlasher closed 5 years ago

CrazyFlasher commented 5 years ago

What is the best way to duplicate SkeletonAnimation? Calling buildSpriteSkeleton many times causes memory leaks and crash. Especially, if setting isNative to true

rainyt commented 5 years ago

In general, SkeletonData objects are reused, and multiple buildSpriteSkeletons do not generate a large number of SkeletonData objects. Is there a more detailed information on the object of the memory leak?

Is there a Sprite object leak that can be used with isNative? I didn't do ObjectPool processing on Sprite

CrazyFlasher commented 5 years ago

Simple example that causes crash during short period of time

        var openflSprite:SkeletonAnimation;

        spineTextureAtals.load(function(textureAtals:SpineTextureAtals):Void{

            Lib.setInterval(() -> {
                if (openflSprite != null)
                {
                    openflSprite.parent.removeChild(openflSprite);
                    openflSprite = null;
                }

                openflSprite = textureAtals.buildSpriteSkeleton("wild",jsonData);
                this.addChild(openflSprite);
                openflSprite.y = 300;
                openflSprite.x = 300;
                openflSprite.play(cast(openflSprite.state.getData().getSkeletonData().animations[0]));
                openflSprite.scaleX = 0.6;
                openflSprite.scaleY = 0.6;
                openflSprite.isNative = true;
            }, 200);
        },function(error:String):Void{
            trace("Error:",error);
        });
CrazyFlasher commented 5 years ago

Looks like calling openflSprite.destroy(); resolved the fast memory leak issue

rainyt commented 5 years ago

Probably because the Event.ENTER_FRAME event did not stop after the object was removed.