Page 1 of 1

Lifetime of Storyboards

Posted: 12 Dec 2024, 20:32
by jhimes144
I have the below static method in a custom control:

static Storyboard getRippleInOutAni(float minScale, float maxScale)

I was wondering how Storyboard's lifetime should be handled. Can it (and all its dependencies such as animation objects) be discarded as soon as Storyboard::Begin is called? Or do I need to create a Noesis Ptr and store it as a field in my control class?

Re: Lifetime of Storyboards

Posted: 12 Dec 2024, 21:23
by sfernandez
Once Storyboard is launched you don't need to keep a reference, as our animation system will keep it alive until the animation is completed.

Just a note on the method you posted, if you're using C++ and that method is creating a new Storyboard object you should return it in a Ptr to keep it alive:
static Ptr<Storyboard> getRippleInOutAni(float minScale, float maxScale)
{
   Ptr<Storyboard> sb = MakePtr<Storyboard>();
   // ...fill in with animations
   return sb;
}

Re: Lifetime of Storyboards

Posted: 13 Dec 2024, 16:38
by jhimes144
Thanks! So then it cannot be created on the stack because the animation system will need to participate in its lifetime, but I don't need to keep a reference. If I were to allocate it on the stack I could expect to run into the assert that is documented here in the C++ architecture document then correct?:
For performance purposes, refcounted instances created in the stack are also supported. In this case is very important to make sure that no extra references are pending at destruction time. BaseRefCounted will assert if that scenario is detected.

Re: Lifetime of Storyboards

Posted: 13 Dec 2024, 17:26
by sfernandez
That's right. Usually you won't allocate BaseRefCounted objects in the stack, unless you have full control over its lifetime, otherwise it could be very risky.