Hello Guest

Author Topic: tk2dSpriteAnimator library has empty clip causing DivideByZeroException  (Read 4178 times)

Neeko

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 59
    • View Profile
    • Overdeveloped
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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
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.

Neeko

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 59
    • View Profile
    • Overdeveloped
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!