[unity] Fixed an exception at SkeletonGraphic when no active attachments are set. MeshGenerator.GenerateSingleSubmeshInstruction() didnt't handle the case of all-null attachments. Improved code to not generate an unnecessary empty instruction. Closes #1491.

This commit is contained in:
Harald Csaszar 2019-09-23 13:09:11 +02:00
parent 6d674c975f
commit e88cfd4dac
2 changed files with 11 additions and 9 deletions

View File

@ -313,7 +313,7 @@ namespace Spine.Unity {
var mesh = smartMesh.mesh; var mesh = smartMesh.mesh;
meshGenerator.FillVertexData(mesh); meshGenerator.FillVertexData(mesh);
if (updateTriangles) meshGenerator.FillTrianglesSingle(mesh); if (updateTriangles) meshGenerator.FillTriangles(mesh);
meshGenerator.FillLateVertexData(mesh); meshGenerator.FillLateVertexData(mesh);
canvasRenderer.SetMesh(mesh); canvasRenderer.SetMesh(mesh);

View File

@ -148,7 +148,6 @@ namespace Spine.Unity {
// Clear last state of attachments and submeshes // Clear last state of attachments and submeshes
instructionOutput.Clear(); // submeshInstructions.Clear(); attachments.Clear(); instructionOutput.Clear(); // submeshInstructions.Clear(); attachments.Clear();
var workingSubmeshInstructions = instructionOutput.submeshInstructions; var workingSubmeshInstructions = instructionOutput.submeshInstructions;
workingSubmeshInstructions.Resize(1);
#if SPINE_TRIANGLECHECK #if SPINE_TRIANGLECHECK
instructionOutput.attachments.Resize(drawOrderCount); instructionOutput.attachments.Resize(drawOrderCount);
@ -206,11 +205,12 @@ namespace Spine.Unity {
current.rawVertexCount += attachmentVertexCount; current.rawVertexCount += attachmentVertexCount;
totalRawVertexCount += attachmentVertexCount; totalRawVertexCount += attachmentVertexCount;
} }
#if !SPINE_TK2D #if !SPINE_TK2D
if (material == null) if (material == null && rendererObject != null)
current.material = (Material)((AtlasRegion)rendererObject).page.rendererObject; current.material = (Material)((AtlasRegion)rendererObject).page.rendererObject;
#else #else
if (material == null) if (material == null && rendererObject != null)
current.material = (rendererObject is Material) ? (Material)rendererObject : (Material)((AtlasRegion)rendererObject).page.rendererObject; current.material = (rendererObject is Material) ? (Material)rendererObject : (Material)((AtlasRegion)rendererObject).page.rendererObject;
#endif #endif
@ -218,7 +218,13 @@ namespace Spine.Unity {
instructionOutput.rawVertexCount = totalRawVertexCount; instructionOutput.rawVertexCount = totalRawVertexCount;
#endif #endif
workingSubmeshInstructions.Items[0] = current; if (totalRawVertexCount > 0) {
workingSubmeshInstructions.Resize(1);
workingSubmeshInstructions.Items[0] = current;
}
else {
workingSubmeshInstructions.Resize(0);
}
} }
public static void GenerateSkeletonRendererInstruction (SkeletonRendererInstruction instructionOutput, Skeleton skeleton, Dictionary<Slot, Material> customSlotMaterials, List<Slot> separatorSlots, bool generateMeshOverride, bool immutableTriangles = false) { public static void GenerateSkeletonRendererInstruction (SkeletonRendererInstruction instructionOutput, Skeleton skeleton, Dictionary<Slot, Material> customSlotMaterials, List<Slot> separatorSlots, bool generateMeshOverride, bool immutableTriangles = false) {
@ -1045,10 +1051,6 @@ namespace Spine.Unity {
for (int i = 0; i < submeshCount; i++) for (int i = 0; i < submeshCount; i++)
mesh.SetTriangles(submeshesItems[i].Items, i, false); mesh.SetTriangles(submeshesItems[i].Items, i, false);
} }
public void FillTrianglesSingle (Mesh mesh) {
mesh.SetTriangles(submeshes.Items[0].Items, 0, false);
}
#endregion #endregion
public void EnsureVertexCapacity (int minimumVertexCount, bool inlcudeTintBlack = false, bool includeTangents = false, bool includeNormals = false) { public void EnsureVertexCapacity (int minimumVertexCount, bool inlcudeTintBlack = false, bool includeTangents = false, bool includeNormals = false) {