Lifetime of Storyboards
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?
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?
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Lifetime of Storyboards
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:
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:
Code: Select all
static Ptr<Storyboard> getRippleInOutAni(float minScale, float maxScale)
{
Ptr<Storyboard> sb = MakePtr<Storyboard>();
// ...fill in with animations
return sb;
}Re: Lifetime of Storyboards
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.
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Lifetime of Storyboards
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