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

prevent crash when destroying sprites in an anim callback #2785

Merged
merged 1 commit into from
Apr 30, 2023

Conversation

Geokureli
Copy link
Member

fixes #2782

The following example will crash without this fix

import flixel.FlxG;
import flixel.FlxSprite;

class AnimCallbackTestState extends flixel.FlxState
{
    override function create()
    {
        var sprite:FlxSprite = new FlxSprite().makeGraphic(100, 100);
        sprite.animation.add("anim", [0, 0, 0, 0], 4, false);
        add(sprite);
        
        // insert animation code here
        sprite.animation.finishCallback = function(anim:String)
        {
            sprite.destroy();
        }
        
        sprite.animation.play('anim');
    }
}

The issue is that parent is referenced internally after the finishCallback is fired. Specifically the callback fired in set_curFrame from FlxAnimation.hx#L218 and parent is referenced in FlxAnimation.hx#L220

@Geokureli Geokureli merged commit 161df9a into HaxeFlixel:dev Apr 30, 2023
@Geokureli Geokureli deleted the anim-finish-null-ref branch May 1, 2023 17:23
@Geokureli Geokureli changed the title prevent crash when destroying sprites in a anim callback prevent crash when destroying sprites in an anim callback May 7, 2023
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

Successfully merging this pull request may close these issues.

Null Object Reference when destroying something with an FlxAnimation on finishCallback
1 participant