When is it safe to destroy an animation instance

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

cheshirekow
Just popping in
Just popping in
Posts: 8
Joined: Tue Apr 03, 2012 21:36

When is it safe to destroy an animation instance

Postby cheshirekow » Tue Apr 10, 2012 17:55

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?

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: When is it safe to destroy an animation instance

Postby Kulik » Tue Apr 10, 2012 19:50

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?

cheshirekow
Just popping in
Just popping in
Posts: 8
Joined: Tue Apr 03, 2012 21:36

Re: When is it safe to destroy an animation instance

Postby cheshirekow » Tue Apr 10, 2012 21:45

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.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 31 guests