From bd7f7eb1819b2e9d8dd521695a43a0a938973b39 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 31 May 2022 19:31:58 +0200 Subject: [PATCH] [unity] Fixed Editor OutOfBoundsException at SkeletonGraphic when switching to skin with more vertices. Closes #2089. --- .../Runtime/spine-unity/Components/SkeletonGraphic.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs index 0fa4af5fb..fdadf6a72 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs @@ -653,7 +653,15 @@ namespace Spine.Unity { var smartMesh = meshBuffers.GetNext(); bool updateTriangles = SkeletonRendererInstruction.GeometryNotEqual(currentInstructions, smartMesh.instructionUsed); meshGenerator.Begin(); - if (currentInstructions.hasActiveClipping && currentInstructions.submeshInstructions.Count > 0) { + + 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 { meshGenerator.BuildMeshWithArrays(currentInstructions, updateTriangles);