From 67f09f79ed5b7fb1b7b52eaf3328dcd32fec8a8b Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Sat, 19 Apr 2025 12:31:28 -0400 Subject: [PATCH] [libgdx] Clear skeleton if update fails instead of crashing. --- .../spine/SkeletonViewer.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java b/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java index 07fa08637..47e574c43 100644 --- a/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java +++ b/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java @@ -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);