修复可能的null引用报错

This commit is contained in:
ww-rm
2025-08-01 00:00:54 +08:00
parent 3eb9b1d008
commit 6dea656e5e

View File

@@ -478,7 +478,6 @@ namespace Spine
} }
var attachment = slot.Attachment; var attachment = slot.Attachment;
SFML.Graphics.Texture texture;
float[] worldVertices; // 顶点世界坐标数组, 连续的 [x0, y0, x1, y1, ...] 坐标值 float[] worldVertices; // 顶点世界坐标数组, 连续的 [x0, y0, x1, y1, ...] 坐标值
int worldVerticesLength; // 顶点数组的长度 int worldVerticesLength; // 顶点数组的长度
@@ -491,10 +490,11 @@ namespace Spine
float tintB = _skeleton.B * slot.B; float tintB = _skeleton.B * slot.B;
float tintA = _skeleton.A * slot.A; float tintA = _skeleton.A * slot.A;
SFML.Graphics.Texture texture;
switch (attachment) switch (attachment)
{ {
case IRegionAttachment regionAttachment: case IRegionAttachment regionAttachment:
texture = regionAttachment.RendererObject;
worldVerticesLength = regionAttachment.ComputeWorldVertices(slot, ref _worldVertices); worldVerticesLength = regionAttachment.ComputeWorldVertices(slot, ref _worldVertices);
worldVertices = _worldVertices; worldVertices = _worldVertices;
triangles = regionAttachment.Triangles; triangles = regionAttachment.Triangles;
@@ -504,9 +504,11 @@ namespace Spine
tintG *= regionAttachment.G; tintG *= regionAttachment.G;
tintB *= regionAttachment.B; tintB *= regionAttachment.B;
tintA *= regionAttachment.A; tintA *= regionAttachment.A;
// NOTE: RenderObject 的获取要在 ComputeWorldVertices 发生之后, 否则可能存在某些 Region 尚未被赋值产生 null 引用报错
texture = regionAttachment.RendererObject;
break; break;
case IMeshAttachment meshAttachment: case IMeshAttachment meshAttachment:
texture = meshAttachment.RendererObject;
worldVerticesLength = meshAttachment.ComputeWorldVertices(slot, ref _worldVertices); worldVerticesLength = meshAttachment.ComputeWorldVertices(slot, ref _worldVertices);
worldVertices = _worldVertices; worldVertices = _worldVertices;
triangles = meshAttachment.Triangles; triangles = meshAttachment.Triangles;
@@ -516,9 +518,9 @@ namespace Spine
tintG *= meshAttachment.G; tintG *= meshAttachment.G;
tintB *= meshAttachment.B; tintB *= meshAttachment.B;
tintA *= meshAttachment.A; tintA *= meshAttachment.A;
texture = meshAttachment.RendererObject;
break; break;
case ISkinnedMeshAttachment skinnedMeshAttachment: case ISkinnedMeshAttachment skinnedMeshAttachment:
texture = skinnedMeshAttachment.RendererObject;
worldVerticesLength = skinnedMeshAttachment.ComputeWorldVertices(slot, ref _worldVertices); worldVerticesLength = skinnedMeshAttachment.ComputeWorldVertices(slot, ref _worldVertices);
worldVertices = _worldVertices; worldVertices = _worldVertices;
triangles = skinnedMeshAttachment.Triangles; triangles = skinnedMeshAttachment.Triangles;
@@ -528,6 +530,7 @@ namespace Spine
tintG *= skinnedMeshAttachment.G; tintG *= skinnedMeshAttachment.G;
tintB *= skinnedMeshAttachment.B; tintB *= skinnedMeshAttachment.B;
tintA *= skinnedMeshAttachment.A; tintA *= skinnedMeshAttachment.A;
texture = skinnedMeshAttachment.RendererObject;
break; break;
case IClippingAttachment clippingAttachment: case IClippingAttachment clippingAttachment:
_clipping.ClipStart(slot, clippingAttachment); _clipping.ClipStart(slot, clippingAttachment);