Fix instance/mesh side-index mismatch in Mesh CAPS upload; validate mesh references and root objects, ensure safe viewer failure and state reset. Add .NET 10 regression and CI gate. No change to HGSP2 or optional S3 features.
52 lines
2.6 KiB
C#
52 lines
2.6 KiB
C#
using OpenSim.Region.ClientStack.Linden;
|
|
|
|
static void Check(bool result, string message)
|
|
{
|
|
if (!result) throw new InvalidOperationException(message);
|
|
}
|
|
|
|
// The actual stacktrace case: one mesh reused by three instances.
|
|
// Previously the loop used meshesSides[instanceIndex], so instance #2
|
|
// could access the one-element mesh sides array outside bounds.
|
|
int[] meshSides = { 7 };
|
|
foreach (int instanceIndex in new[] { 0, 1, 2 })
|
|
{
|
|
Check(MeshUploadIndexGuard.TryResolveSides(0, 1, meshSides, 3, out int faces),
|
|
$"Instance {instanceIndex}: shared mesh index unexpectedly rejected");
|
|
Check(faces == 7, $"Instance {instanceIndex}: mesh side count differs by instance");
|
|
}
|
|
|
|
// Different instances can refer to meshes in any order; the side count
|
|
// belongs to the referenced mesh, not the object's position in the list.
|
|
int[] mixedSides = { 3, 9 };
|
|
foreach (var test in new[] {(index: 1, expected: 9), (index: 0, expected: 3), (index: 1, expected: 9)})
|
|
{
|
|
Check(MeshUploadIndexGuard.TryResolveSides(test.index, 2, mixedSides, 2, out int sides),
|
|
"Valid mesh instance rejected");
|
|
Check(sides == test.expected, "Wrong mesh-side array index used");
|
|
}
|
|
|
|
// Fee-side arrays may be null, partial, or contain an invalid zero entry.
|
|
// These cases fall back to the uploaded instance's face count.
|
|
Check(MeshUploadIndexGuard.TryResolveSides(1, 2, new[] { 3 }, 4, out int fallback)
|
|
&& fallback == 4, "Short mesh-side list should use instance face count");
|
|
Check(MeshUploadIndexGuard.TryResolveSides(0, 1, null, 6, out fallback)
|
|
&& fallback == 6, "Null mesh-side list should use instance face count");
|
|
Check(MeshUploadIndexGuard.TryResolveSides(0, 1, new[] { 0 }, 4, out fallback)
|
|
&& fallback == 4, "Zero mesh-side value must fall back");
|
|
Check(MeshUploadIndexGuard.TryResolveSides(0, 1, new[] { 0 }, 0, out fallback)
|
|
&& fallback == 1, "Mesh must receive at least one side");
|
|
|
|
// Invalid index references must be rejected, never silently used.
|
|
Check(!MeshUploadIndexGuard.TryResolveSides(-1, 1, meshSides, 3, out _),
|
|
"Negative mesh index accepted");
|
|
Check(!MeshUploadIndexGuard.TryResolveSides(1, 1, meshSides, 3, out _),
|
|
"Out-of-range mesh index accepted");
|
|
Check(!MeshUploadIndexGuard.TryResolveSides(0, 0, meshSides, 3, out _),
|
|
"Missing mesh accepted");
|
|
Check(!MeshUploadIndexGuard.HasRenderableRoot(0),
|
|
"All filtered instances must not cause positions[0] access");
|
|
Check(MeshUploadIndexGuard.HasRenderableRoot(2),
|
|
"Valid model must keep its root instance");
|
|
Console.WriteLine("OGL mesh CAPS instance/mesh index, side fallback, negative index and empty root: PASS");
|