Page 1 of 1

When is it safe to destroy an animation instance

Posted: Tue Apr 10, 2012 17:55
by cheshirekow
In my code, I destroy an animation instance in the CEGUI::AnimationInstance::EventAnimationEnded handler. This works on my linux build but in my iPhone build the instance is destroyed before it is removed from the AnimationManager. At least, thats what I gather from the debugger... I get a memory error which halts the program in AnimationManager::stepInstances (on the iPhone simulator).

I've been looking at the code and it seems that the Animation Manager stores animation instances as a map Animation* -> AnimationInstance*. It appears that destroyAnimationInstance removes the element from the map. IIRC any time you erase something from a map any current read iterators become invalid. Perhaps this is incidentally not the case in the std::map implementation on my linux system, but is the case for the iPhone system (though they both appear to use red-black tree's for the implementation).

Anyway, whats the best way to destroy animation instances when they are finished?

Re: When is it safe to destroy an animation instance

Posted: Tue Apr 10, 2012 19:50
by Kulik
You are right, deleting an animation instance while the system is stepping them breaks the iterator.

I think AnimationInstances need a dead pool like Windows have. Are you interested in creating a patch for this?

Re: When is it safe to destroy an animation instance

Posted: Tue Apr 10, 2012 21:45
by cheshirekow
Should be easy enough. I'll need to do something for my application anyhow since I'm dynamically creating one-off animations. If I can do it cleanly I'll submit a patch.