I found the exact reason why it happened. Yeah, as you said that SimpleTest1 works fine even though I called addAnimation
sequentially with a same animation, but if you change an animation during the end
event of AnimationStateAdapter
, it throws the exception.
Here is a code snippet of modified version of SimpleTest1
state.setAnimation(0, "run", false);
state.addAnimation(0, "idle", true, 0);
state.addAnimation(0, "idle", true, 0); <
---
This line, actually any animation can cause a problem
state.addListener(new AnimationState.AnimationStateAdapter() {
@Override
public void end(int trackIndex) {
if(!firstTime){
firstTime = true;
Gdx.app.log("end animation", "");
state.setAnimation(0, "jump", true); <
---
if you change an animation here, NPE will be thrown
}
}
});
Nate schriebWait, you got an NPE but never posted the stacktrace?
Sorry man, my bad :$
Here is a stacktrace
Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.esotericsoftware.spine.AnimationStateData$Key.hashCode(AnimationStateData.java:87)
at com.badlogic.gdx.utils.ObjectFloatMap.get(ObjectFloatMap.java:279)
at com.esotericsoftware.spine.AnimationStateData.getMix(AnimationStateData.java:72)
at com.esotericsoftware.spine.AnimationState.setCurrent(AnimationState.java:191)
at com.esotericsoftware.spine.AnimationState.update(AnimationState.java:74)
at com.esotericsoftware.spine.SimpleTest1.render(SimpleTest1.java:96)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:223)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)