Skip to content

Commit

Permalink
[unity] Fixed editor OutOfBoundsException at SkeletonGraphic when swi…
Browse files Browse the repository at this point in the history
…tching to skin with more vertices while preventing another exception (occurred after fix bd7f7eb). Closes #2089.
  • Loading branch information
HaraldCsaszar committed Aug 19, 2022
1 parent e7ee3f4 commit 3d24846
Showing 1 changed file with 5 additions and 19 deletions.
Expand Up @@ -114,6 +114,11 @@ public class SkeletonGraphic : MaskableGraphic, ISkeletonComponent, IAnimationSt
} else {
if (freeze) return;

if (!Application.isPlaying) {
Initialize(true);
return;
}

if (!string.IsNullOrEmpty(initialSkinName)) {
var skin = skeleton.Data.FindSkin(initialSkinName);
if (skin != null) {
Expand All @@ -124,19 +129,6 @@ public class SkeletonGraphic : MaskableGraphic, ISkeletonComponent, IAnimationSt
}

}

// 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
Expand Down Expand Up @@ -727,12 +719,6 @@ public class SkeletonGraphic : MaskableGraphic, ISkeletonComponent, IAnimationSt
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 {
Expand Down

0 comments on commit 3d24846

Please sign in to comment.