acdream/tests/AcDream.App.Tests/Rendering/Wb/InstanceGroupClearTests.cs
Erik ea4f52ec51 fix(selection): port SmartBox click lighting pulse
Port the retail high/low material-lighting cadence for successful world clicks, keep it instance-scoped in the modern renderer, and restore authored lighting after 0.8 seconds. Correct the selection oracle and pin timing plus per-frame buffer lifecycle with tests.

Co-authored-by: Codex <codex@openai.com>
2026-07-17 23:00:04 +02:00

37 lines
1.5 KiB
C#

using System.Numerics;
using AcDream.App.Rendering.Wb;
using Xunit;
namespace AcDream.App.Tests.Rendering.Wb;
public class InstanceGroupClearTests
{
// #193 (regression from #188, 2026-07-09): WbDrawDispatcher's InstanceGroup holds
// six per-instance parallel lists — Matrices, Slots, LightSets, IndoorFlags,
// Opacities, SelectionLighting — appended in lockstep (one entry per drawn instance) every frame. The
// per-frame reset must clear ALL of them. #188 added Opacities but left it out of
// the inline clear loop, so it grew one float per instance per frame forever; as
// List<float>'s backing array doubled it produced ~128 MB / ~512 MB LOH float[]
// arrays and leaked ~1 GB/min -> OOM after ~50 min of play. This test pins that
// every parallel list is reset, so a newly-added list can't silently drift again.
[Fact]
public void ClearPerInstanceData_ClearsEveryParallelPerInstanceList()
{
var grp = new WbDrawDispatcher.InstanceGroup();
grp.Matrices.Add(Matrix4x4.Identity);
grp.Slots.Add(1u);
grp.LightSets.Add(-1);
grp.IndoorFlags.Add(0u);
grp.Opacities.Add(1.0f);
grp.SelectionLighting.Add(new Vector2(0f, 1f));
grp.ClearPerInstanceData();
Assert.Empty(grp.Matrices);
Assert.Empty(grp.Slots);
Assert.Empty(grp.LightSets);
Assert.Empty(grp.IndoorFlags);
Assert.Empty(grp.Opacities); // #193 — the list that leaked
Assert.Empty(grp.SelectionLighting);
}
}