Elsch

Animation.java:538 (Animation$EventTimeline.apply(...)):
binarySearch(frames, lastTime, 1) is called.
I have an animation with just a single event firing at some point.
This causes frames to have just one entry at this point. Therefore in...
Animation.java:112 (Animation.binarySearch(...)):
int high = values.length / step - 2; // 1 / 1 - 2 = -1
int current = high >>> 1;
...sets current to 2147483647 leading to an ArrayIndexOutOfBoundsException in the process.
Elsch

Epic Kickstarter Backer
  • 記事: 7

Elsch

I had a quick look at the other timelines, especially the AttachementTimeline. I guess there is just one more check missing in case time has passed beyond the last frame. This works for me:
public void apply (Skeleton skeleton, float lastTime, float time, float alpha, Array<Event> firedEvents) {
float[] frames = this.frames;
if (time < frames[0]) return; // Time is before first frame.

int frameCount = frames.length;
if (lastTime >= frames[frameCount - 1]) return; // Last time is after last frame.

int frameIndex;
if (time >= frames[frames.length - 1]) // Time is after last frame.
frameIndex = frames.length - 1;
else
frameIndex = binarySearch(frames, time, 1) - 1;

float frame = frames[frameIndex];
while (frameIndex > 0 && frame == frames[frameIndex - 1])
frameIndex--; // Fire multiple events with the same frame.
for (; frameIndex < frameCount && time > frames[frameIndex]; frameIndex++)
firedEvents.add(events[frameIndex]);
}
Elsch

Epic Kickstarter Backer
  • 記事: 7

Nate

I had forgot to push this fix. :( In now, sorry!
アバター
Nate

Nate
  • 記事: 9655

Cuellarjmcg

Nate さんが書きました:I had forgot to push this fix. :( In now, sorry!
Mmm the exception is gone, but the event isn't fired. End, Start and Complete works without problem, but event doesn't :(

Tried with the same project that I attached at this post:

viewtopic.php?f=9&t=1098

The listener:
animState.addListener(new AnimationStateListener() {
public void event (Event event) {
Gdx.app.log(Game.LOG, "Event: " + event.getData().getName());
}
public void complete (int loopCount) {
Gdx.app.log(Game.LOG, "Complete: " + animState.getAnimation() + ", " + loopCount);
}
public void start () {
Gdx.app.log(Game.LOG, "Start: " + animState.getAnimation());
}
public void end () {
Gdx.app.log(Game.LOG, "End: " + animState.getAnimation());
}
});
The result:

GAMELOG: Start: animdisprotardisparo
GAMELOG: Complete: animdisprotardisparo, 1
GAMELOG: End: animdisprotardisparo
Cuellarjmcg

Kickstarter Backer
  • 記事: 92

Nate

Exported your project, jammed it into SkeletonTest (JSON), works for me. I see [sonido] in the logs. Using pambagenerico skeleton and animdisprotardisparo animation.
アバター
Nate

Nate
  • 記事: 9655

Cuellarjmcg

Nate さんが書きました:Exported your project, jammed it into SkeletonTest (JSON), works for me. I see [sonido] in the logs. Using pambagenerico skeleton and animdisprotardisparo animation.
Mmm I'll take a look at my end, maybe has to do with the updating of the skeleton, thanks for the confirmation.
Cuellarjmcg

Kickstarter Backer
  • 記事: 92

Cuellarjmcg

Well, I had to update / apply the AnimationState at draw method so events stay in sync, now it works.

What I did before is that at render method from the Screen, I had an update section and draw section, so at update I was updating the state, but I guess events get lost if I don't apply the animation after that (because of lastTime and time). That helped me sync some a lot of things, like particles, actions and so on, but I think I can get around it.

I like that AnimationState controls the mixing of animations and events so... I guess is a little trade off ;)
Cuellarjmcg

Kickstarter Backer
  • 記事: 92

Nate

Ah, I see. I've changed things so update can be called any number of times and the "last time" used is always the last time apply() was called. Thanks!
アバター
Nate

Nate
  • 記事: 9655

Cuellarjmcg

Nate さんが書きました:Ah, I see. I've changed things so update can be called any number of times and the "last time" used is always the last time apply() was called. Thanks!
Whoa! really nice, thanks a lot Nate :)
Cuellarjmcg

Kickstarter Backer
  • 記事: 92


Return to Bugs