jhimes144
Topic Author
Posts: 16
Joined: 19 Nov 2024, 01:36

Lifetime of Storyboards

12 Dec 2024, 20:32

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?
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Lifetime of Storyboards

12 Dec 2024, 21:23

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;
}
 
jhimes144
Topic Author
Posts: 16
Joined: 19 Nov 2024, 01:36

Re: Lifetime of Storyboards

13 Dec 2024, 16:38

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.
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Lifetime of Storyboards

13 Dec 2024, 17:26

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.

Who is online

Users browsing this forum: No registered users and 6 guests