Skip to content

Commit 7a31117

Browse files
committed
FIX: Error disposing source in getInternalAnimations.
1 parent b84217d commit 7a31117

File tree

2 files changed

+58
-32
lines changed

2 files changed

+58
-32
lines changed

adventure-editor/src/main/java/com/bladecoder/engineeditor/common/EditorLogger.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.badlogic.gdx.scenes.scene2d.InputEvent;
2727
import com.badlogic.gdx.scenes.scene2d.InputListener;
2828
import com.badlogic.gdx.scenes.scene2d.Stage;
29+
import com.bladecoder.engine.util.EngineLogger;
2930
import com.bladecoder.engineeditor.Ctx;
3031
import com.strongjoshua.console.CommandExecutor;
3132
import com.strongjoshua.console.Console;
@@ -160,9 +161,13 @@ public void debug(boolean value) {
160161
if (!value) {
161162
level = Levels.ERROR;
162163
console.setLoggingToSystem(false);
164+
165+
if(EngineLogger.debugMode())
166+
EngineLogger.toggle();
163167
} else {
164168
level = Levels.DEBUG;
165169
console.setLoggingToSystem(true);
170+
EngineLogger.setDebug();
166171
}
167172
}
168173

blade-engine-spine-plugin/src/main/java/com/bladecoder/engine/spine/SpineRenderer.java

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.badlogic.gdx.math.Matrix4;
2424
import com.badlogic.gdx.math.Vector2;
2525
import com.badlogic.gdx.utils.Array;
26+
import com.badlogic.gdx.utils.GdxRuntimeException;
2627
import com.badlogic.gdx.utils.Json;
2728
import com.badlogic.gdx.utils.JsonValue;
2829
import com.bladecoder.engine.actions.ActionCallback;
@@ -68,7 +69,7 @@ public class SpineRenderer extends AnimationRenderer {
6869

6970
private SkeletonRenderer<SpriteBatch> renderer;
7071
private SkeletonBounds bounds;
71-
72+
7273
private float width = super.getWidth(), height = super.getHeight();
7374

7475
private float lastAnimationTime = 0;
@@ -101,8 +102,8 @@ public void complete(int trackIndex, int loopCount) {
101102
&& (currentCount == Tween.INFINITY || currentCount > loopCount)) {
102103

103104
// FIX for latest spine rt not setting setup pose when looping.
104-
SkeletonCacheEntry cs = (SkeletonCacheEntry)currentSource;
105-
105+
SkeletonCacheEntry cs = (SkeletonCacheEntry) currentSource;
106+
106107
cs.skeleton.setToSetupPose();
107108
cs.skeleton.setFlipX(flipX);
108109
complete = true;
@@ -169,9 +170,19 @@ public void start(int arg0) {
169170

170171
@Override
171172
public String[] getInternalAnimations(AnimationDesc anim) {
172-
retrieveSource(anim.source, ((SpineAnimationDesc) anim).atlas);
173+
try {
174+
retrieveSource(anim.source, ((SpineAnimationDesc) anim).atlas);
175+
} catch (GdxRuntimeException e) {
176+
sourceCache.remove(anim.source);
177+
Array<String> dependencies = EngineAssetManager.getInstance().getDependencies(getFileName(anim.source));
178+
if(dependencies.size > 0)
179+
dependencies.removeIndex(dependencies.size - 1);
180+
return new String[0];
181+
}
173182

174-
Array<Animation> animations = ((SkeletonCacheEntry)sourceCache.get(anim.source)).skeleton.getData().getAnimations();
183+
Array<Animation> animations = ((SkeletonCacheEntry) sourceCache.get(anim.source)).skeleton.getData()
184+
.getAnimations();
185+
175186
String[] result = new String[animations.size];
176187

177188
for (int i = 0; i < animations.size; i++) {
@@ -188,7 +199,7 @@ public void update(float delta) {
188199
return;
189200
}
190201

191-
if (currentSource != null && ((SkeletonCacheEntry)currentSource).skeleton != null) {
202+
if (currentSource != null && ((SkeletonCacheEntry) currentSource).skeleton != null) {
192203
float d = delta;
193204

194205
if (currentAnimationType == Tween.Type.REVERSE) {
@@ -210,7 +221,7 @@ public void update(float delta) {
210221

211222
private void updateAnimation(float time) {
212223
SkeletonCacheEntry cs = (SkeletonCacheEntry) currentSource;
213-
224+
214225
cs.animation.update(time);
215226
cs.animation.apply(cs.skeleton);
216227
cs.skeleton.updateWorldTransform();
@@ -222,18 +233,18 @@ private void updateAnimation(float time) {
222233
public void draw(SpriteBatch batch, float x, float y, float scale, float rotation, Color tint) {
223234

224235
SkeletonCacheEntry cs = (SkeletonCacheEntry) currentSource;
225-
236+
226237
if (cs != null && cs.skeleton != null) {
227238
Matrix4 tm = batch.getTransformMatrix();
228239
tmp.set(tm);
229240

230241
float originX = cs.skeleton.getRootBone().getX();
231242
float originY = cs.skeleton.getRootBone().getY();
232-
tm.translate(x,y,0).rotate(0, 0, 1, rotation).scale(scale, scale, 1).translate(originX, originY, 0);
233-
234-
// cs.skeleton.setX(x / scale);
235-
// cs.skeleton.setY(y / scale);
236-
243+
tm.translate(x, y, 0).rotate(0, 0, 1, rotation).scale(scale, scale, 1).translate(originX, originY, 0);
244+
245+
// cs.skeleton.setX(x / scale);
246+
// cs.skeleton.setY(y / scale);
247+
237248
batch.setTransformMatrix(tm);
238249

239250
if (tint != null)
@@ -247,8 +258,9 @@ public void draw(SpriteBatch batch, float x, float y, float scale, float rotatio
247258
} else {
248259
float dx = getAlignDx(getWidth(), orgAlign);
249260
float dy = getAlignDy(getHeight(), orgAlign);
250-
251-
RectangleRenderer.draw(batch, x + dx * scale , y + dy * scale, getWidth() * scale, getHeight() * scale, Color.RED);
261+
262+
RectangleRenderer.draw(batch, x + dx * scale, y + dy * scale, getWidth() * scale, getHeight() * scale,
263+
Color.RED);
252264
}
253265
}
254266

@@ -339,7 +351,7 @@ public void startAnimation(String id, Tween.Type repeatType, int count, ActionCa
339351

340352
if (currentAnimationType == Tween.Type.REVERSE) {
341353
// get animation duration
342-
Array<Animation> animations = ((SkeletonCacheEntry)currentSource).skeleton.getData().getAnimations();
354+
Array<Animation> animations = ((SkeletonCacheEntry) currentSource).skeleton.getData().getAnimations();
343355

344356
for (Animation a : animations) {
345357
if (a.getName().equals(currentAnimation.id)) {
@@ -380,7 +392,7 @@ public void computeBbox() {
380392
if (bbox != null && (bbox.getVertices() == null || bbox.getVertices().length != 8)) {
381393
bbox.setVertices(new float[8]);
382394
}
383-
395+
384396
SkeletonCacheEntry cs = (SkeletonCacheEntry) currentSource;
385397

386398
if (cs == null || cs.skeleton == null) {
@@ -542,9 +554,15 @@ private AnimationDesc getAnimation(String id) {
542554

543555
return fa;
544556
}
557+
558+
559+
private String getFileName(String source) {
560+
return EngineAssetManager.SPINE_DIR + source + EngineAssetManager.SPINE_EXT;
561+
}
545562

546563
private void loadSource(String source, String atlas) {
547-
SkeletonCacheEntry entry = (SkeletonCacheEntry)sourceCache.get(source);
564+
EngineLogger.debug("Loading: " + source);
565+
SkeletonCacheEntry entry = (SkeletonCacheEntry) sourceCache.get(source);
548566

549567
if (entry == null) {
550568
entry = new SkeletonCacheEntry();
@@ -553,34 +571,35 @@ private void loadSource(String source, String atlas) {
553571
}
554572

555573
if (entry.refCounter == 0) {
556-
557-
if(EngineAssetManager.getInstance().getLoader(SkeletonData.class) == null) {
574+
575+
if (EngineAssetManager.getInstance().getLoader(SkeletonData.class) == null) {
558576
EngineAssetManager.getInstance().setLoader(SkeletonData.class,
559577
new SkeletonDataLoader(EngineAssetManager.getInstance().getFileHandleResolver()));
560578
}
561-
579+
562580
SkeletonDataLoaderParameter parameter = new SkeletonDataLoaderParameter(
563581
EngineAssetManager.ATLASES_DIR + entry.atlas + EngineAssetManager.ATLAS_EXT,
564582
EngineAssetManager.getInstance().getScale());
565-
EngineAssetManager.getInstance().load(EngineAssetManager.SPINE_DIR + source + EngineAssetManager.SPINE_EXT,
583+
EngineAssetManager.getInstance().load(getFileName(source),
566584
SkeletonData.class, parameter);
567585
}
568586

569587
entry.refCounter++;
570588
}
571589

572590
private void retrieveSource(String source, String atlas) {
573-
SkeletonCacheEntry entry = (SkeletonCacheEntry)sourceCache.get(source);
591+
EngineLogger.debug("Retrieving: " + source);
592+
SkeletonCacheEntry entry = (SkeletonCacheEntry) sourceCache.get(source);
574593

575594
if (entry == null || entry.refCounter < 1) {
576595
loadSource(source, atlas);
577596
EngineAssetManager.getInstance().finishLoading();
578-
entry = (SkeletonCacheEntry)sourceCache.get(source);
597+
entry = (SkeletonCacheEntry) sourceCache.get(source);
579598
}
580599

581600
if (entry.skeleton == null) {
582601
SkeletonData skeletonData = EngineAssetManager.getInstance()
583-
.get(EngineAssetManager.SPINE_DIR + source + EngineAssetManager.SPINE_EXT, SkeletonData.class);
602+
.get(getFileName(source), SkeletonData.class);
584603

585604
entry.skeleton = new Skeleton(skeletonData);
586605

@@ -596,10 +615,12 @@ private void retrieveSource(String source, String atlas) {
596615
}
597616

598617
private void disposeSource(String source) {
599-
SkeletonCacheEntry entry = (SkeletonCacheEntry)sourceCache.get(source);
618+
EngineLogger.debug("Disposing: " + source);
619+
SkeletonCacheEntry entry = (SkeletonCacheEntry) sourceCache.get(source);
600620

601621
if (entry.refCounter == 1) {
602-
EngineAssetManager.getInstance().disposeAtlas(source);
622+
EngineAssetManager.getInstance()
623+
.unload(EngineAssetManager.SPINE_DIR + source + EngineAssetManager.SPINE_EXT);
603624
entry.animation = null;
604625
entry.skeleton = null;
605626
}
@@ -632,11 +653,11 @@ public void retrieveAssets() {
632653

633654
for (String key : sourceCache.keySet()) {
634655
if (sourceCache.get(key).refCounter > 0)
635-
retrieveSource(key, ((SkeletonCacheEntry)sourceCache.get(key)).atlas);
656+
retrieveSource(key, ((SkeletonCacheEntry) sourceCache.get(key)).atlas);
636657
}
637658

638659
if (currentAnimation != null) {
639-
SkeletonCacheEntry entry = (SkeletonCacheEntry)sourceCache.get(currentAnimation.source);
660+
SkeletonCacheEntry entry = (SkeletonCacheEntry) sourceCache.get(currentAnimation.source);
640661
currentSource = entry;
641662

642663
// Stop events to avoid event trigger
@@ -670,7 +691,7 @@ public void dispose() {
670691
@Override
671692
public void write(Json json) {
672693
super.write(json);
673-
694+
674695
if (SerializationHelper.getInstance().getMode() == Mode.MODEL) {
675696

676697
} else {
@@ -690,11 +711,11 @@ public void write(Json json) {
690711
@Override
691712
public void read(Json json, JsonValue jsonData) {
692713
super.read(json, jsonData);
693-
714+
694715
if (SerializationHelper.getInstance().getMode() == Mode.MODEL) {
695716
fanims = json.readValue("fanims", HashMap.class, SpineAnimationDesc.class, jsonData);
696717
} else {
697-
718+
698719
String animationCbSer = json.readValue("cb", String.class, jsonData);
699720
animationCb = ActionCallbackSerialization.find(animationCbSer);
700721

0 commit comments

Comments
 (0)