Dangling AnimationTasks Causing Crashes

Hi everyone, I’ve got a slightly unusual situation where I’m dragging tabs around a TabbedButtonBar. There’s an occasional situation where the animation process calls resized on the TabbedButtonBar which then deletes the AnimationTask during the useTimeslice call. This then causes the stack to reference the now deleted AnimationTask.

The stages are as follows:
• During ComponentAnimator::timerCallback the Component’s bounds are changed
• This in turn leads to a parent of the component resizing its children
• This calls ComponentAnimator::cancelAnimation on the currently animating component which deletes the AnimationTask
• The stack then returns to ComponentAnimator::AnimationTask::useTimeslice which is now working on a dangling AnimationTask

I’ve created a patch that I think solves the problem. Could you take a look over it and hopefully merge it in?

Cheers!
ComponentAnimator Diff.txt (2.5 KB)

Cheers Dave, good suggestion, I’ve added it now.

Cheers!
(Padding here)

It turns out that there’s another place we need the WeakRef check:

void moveToFinalDestination()
{
    if (component != nullptr)
    {
        const WeakReference<AnimationTask> weakRef (this);
        component->setAlpha ((float) destAlpha);
        component->setBounds (destination);

        // Check whether the animation was cancelled/deleted during
        // a callback during the setBounds method
        if (weakRef.wasObjectDeleted())
            return;

        if (proxy != nullptr)
            component->setVisible (destAlpha > 0);
    }
}

Ta, will add that too