Browse Source

[unity] Fixed editor OutOfBoundsException at SkeletonGraphic when switching to skin with more vertices while preventing another exception (occurred after fix bd7f7eb1). Closes #2089.

Harald Csaszar 3 years ago
parent
commit
3d2484697a

+ 5 - 19
spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs

@@ -114,6 +114,11 @@ namespace Spine.Unity {
 				} else {
 					if (freeze) return;
 
+					if (!Application.isPlaying) {
+						Initialize(true);
+						return;
+					}
+
 					if (!string.IsNullOrEmpty(initialSkinName)) {
 						var skin = skeleton.Data.FindSkin(initialSkinName);
 						if (skin != null) {
@@ -124,19 +129,6 @@ namespace Spine.Unity {
 						}
 
 					}
-
-					// Only provide visual feedback to inspector changes in Unity Editor Edit mode.
-					if (!Application.isPlaying) {
-						skeleton.ScaleX = this.initialFlipX ? -1 : 1;
-						skeleton.ScaleY = this.initialFlipY ? -1 : 1;
-
-						state.ClearTrack(0);
-						skeleton.SetToSetupPose();
-						if (!string.IsNullOrEmpty(startingAnimation)) {
-							state.SetAnimation(0, startingAnimation, startingLoop);
-							Update(0f);
-						}
-					}
 				}
 			} else {
 				// Under some circumstances (e.g. sometimes on the first import) OnValidate is called
@@ -727,12 +719,6 @@ namespace Spine.Unity {
 			meshGenerator.Begin();
 
 			bool useAddSubmesh = currentInstructions.hasActiveClipping && currentInstructions.submeshInstructions.Count > 0;
-#if UNITY_EDITOR
-			// Editor triggers Graphic.Rebuild without prior LateUpdate call, which
-			// can lead to filling unprepared vertex buffer and out-of-bounds write access.
-			if (!Application.isPlaying)
-				useAddSubmesh = true;
-#endif
 			if (useAddSubmesh) {
 				meshGenerator.AddSubmesh(currentInstructions.submeshInstructions.Items[0], updateTriangles);
 			} else {