2D Toolkit Forum

2D Toolkit => Support => Topic started by: Neeko on June 29, 2014, 08:22:21 pm

Title: tk2dSpriteAnimator library has empty clip causing DivideByZeroException
Post by: Neeko on June 29, 2014, 08:22:21 pm
I have a tk2dSpriteAnimator with a collection of tk2dSpriteAnimationClips. For some reason, an empty tk2dSpriteAnimationClip (empty being that the Empty property is true, there are no frames, and the name is empty string) is being inserted into the Library.clips array. Since I randomly choose a clip to play within the library, if this empty clip is selected I receive a DivideByZeroException in tk2dSpriteAnimator, line 686 (
Code: [Select]
int frameId = (int)clipTime % clip.frames.Length;).

Why is an empty clip being inserted into the clips array? I do not have this clip specified in the sprite animation editor.
Title: Re: tk2dSpriteAnimator library has empty clip causing DivideByZeroException
Post by: unikronsoftware on June 29, 2014, 08:27:18 pm
A clip is empty when it is deleted, it is never removed from the list to retain index order. We could transparently return when the clip is empty but thats probably not what you want, you should make sure its not empty if you're simply finding a random clip. Alternatively, on startup you can make a list of all tk2dSpriteAnimationClip references that are not empty and pick from that.
Title: Re: tk2dSpriteAnimator library has empty clip causing DivideByZeroException
Post by: Neeko on June 29, 2014, 08:52:56 pm
I'll just check for the empty clip when I randomly select. I just wanted to make sure I didn't come across a bug within the framework. Thanks for the quick response!