[libgdx] Clear skeleton if update fails instead of crashing.

This commit is contained in:
Nathan Sweet 2025-04-19 12:31:28 -04:00
parent 2c6b43a9c2
commit 67f09f79ed

View File

@ -32,6 +32,8 @@ package com.esotericsoftware.spine;
import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.Field;
import org.lwjgl.system.Configuration;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
@ -53,7 +55,6 @@ import com.esotericsoftware.spine.Animation.MixBlend;
import com.esotericsoftware.spine.AnimationState.AnimationStateAdapter;
import com.esotericsoftware.spine.AnimationState.TrackEntry;
import com.esotericsoftware.spine.utils.TwoColorPolygonBatch;
import org.lwjgl.system.Configuration;
import java.awt.Toolkit;
@ -195,6 +196,14 @@ public class SkeletonViewer extends ApplicationAdapter {
return true;
}
void clearSkeleton () {
skeleton = null;
state = null;
ui.skinList.clearItems();
ui.animationList.clearItems();
ui.statusLabel.setText("");
}
void setAnimation (boolean first) {
if (!ui.prefsLoaded) return;
if (ui.animationList.getSelected() == null) return;
@ -266,10 +275,17 @@ public class SkeletonViewer extends ApplicationAdapter {
skeleton.setupPoseSlots();
delta = Math.min(delta, 0.032f) * ui.speedSlider.getValue();
state.update(delta);
state.apply(skeleton);
skeleton.update(delta);
skeleton.updateWorldTransform(Physics.update);
try {
state.update(delta);
state.apply(skeleton);
skeleton.update(delta);
skeleton.updateWorldTransform(Physics.update);
} catch (Throwable ex) {
ex.printStackTrace();
ui.toast("Error updating skeleton.");
clearSkeleton();
return;
}
batch.begin();
renderer.draw(batch, skeleton);