diff --git a/src/AcDream.App/Rendering/Wb/WbDrawDispatcher.cs b/src/AcDream.App/Rendering/Wb/WbDrawDispatcher.cs index 34c70af0..17a4e259 100644 --- a/src/AcDream.App/Rendering/Wb/WbDrawDispatcher.cs +++ b/src/AcDream.App/Rendering/Wb/WbDrawDispatcher.cs @@ -244,6 +244,13 @@ public sealed unsafe class WbDrawDispatcher : IDisposable private int _instancesIssued; private long _lastLogTick; + // #128 self-heal: per-Draw dedup of point-of-use load re-requests + // (PrepareMeshDataAsync is idempotent while pending — the dedup just + // avoids redundant dictionary probes within one pass) + the once-per-id + // [mesh-miss] diagnostic set (never cleared; diag-gated emission). + private readonly HashSet _missRequested = new(); + private readonly HashSet _missLogged = new(); + // CPU + GPU timing for [WB-DIAG] under ACDREAM_WB_DIAG=1. private readonly System.Diagnostics.Stopwatch _cpuStopwatch = new(); private readonly long[] _cpuSamples = new long[256]; // microseconds @@ -728,6 +735,9 @@ public sealed unsafe class WbDrawDispatcher : IDisposable var vp = camera.View * camera.Projection; _shader.SetMatrix4("uViewProjection", vp); + // #128 self-heal: fresh re-request dedup per Draw pass. + _missRequested.Clear(); + bool diag = string.Equals(Environment.GetEnvironmentVariable("ACDREAM_WB_DIAG"), "1", StringComparison.Ordinal); if (diag && !_gpuQueriesInitialized) @@ -1054,6 +1064,17 @@ public sealed unsafe class WbDrawDispatcher : IDisposable // the populate fires with the complete batch set. currentEntityIncomplete = true; if (diag) _meshesMissing++; + // #128 self-heal: a missing-but-referenced mesh re-requests + // its load HERE — the one site that touches it every frame — + // so a preparation lost to landblock churn (cancelled after + // the last registration event) can never stay lost. Deduped + // per Draw; PrepareMeshDataAsync is idempotent while pending. + if (_missRequested.Add(gfxObjId)) + { + _meshAdapter.EnsureLoaded(gfxObjId); + if (diag && _missLogged.Add(gfxObjId)) + Console.WriteLine($"[mesh-miss] 0x{gfxObjId:X10} re-requested at point of use"); + } continue; } if (anyVao == 0) anyVao = renderData.VAO; @@ -1070,7 +1091,23 @@ public sealed unsafe class WbDrawDispatcher : IDisposable foreach (var (partGfxObjId, partTransform) in renderData.SetupParts) { var partData = _meshAdapter.TryGetRenderData(partGfxObjId); - if (partData is null) continue; + if (partData is null) + { + // #128 self-heal + #53: a missing Setup PART must mark + // the entity incomplete (else a partial batch set + // caches permanently — the same bug class one level + // deeper) and re-request its load like the MeshRef + // path above. + currentEntityIncomplete = true; + if (diag) _meshesMissing++; + if (_missRequested.Add(partGfxObjId)) + { + _meshAdapter.EnsureLoaded(partGfxObjId); + if (diag && _missLogged.Add(partGfxObjId)) + Console.WriteLine($"[mesh-miss] 0x{partGfxObjId:X10} (setup part) re-requested at point of use"); + } + continue; + } var model = ComposePartWorldMatrix( entityWorld, meshRef.PartTransform, partTransform); diff --git a/src/AcDream.App/Rendering/Wb/WbMeshAdapter.cs b/src/AcDream.App/Rendering/Wb/WbMeshAdapter.cs index c3188813..af2940ec 100644 --- a/src/AcDream.App/Rendering/Wb/WbMeshAdapter.cs +++ b/src/AcDream.App/Rendering/Wb/WbMeshAdapter.cs @@ -198,6 +198,26 @@ public sealed class WbMeshAdapter : IDisposable, IWbMeshAdapter _meshManager.DecrementRefCount(id); } + /// + /// #128 self-heal (2026-06-11): re-request a mesh load at the POINT OF + /// USE. Registration-time re-arming was insufficient — a preparation + /// cancelled by landblock churn AFTER the last registration event + /// (running across blocks loads/unloads them repeatedly) left the mesh + /// permanently unloadable with no later event to re-fire it. The draw + /// dispatcher touches every missing-but-referenced mesh every frame (the + /// meshMissing slow path) — that is the one place a retry can never be + /// missed. Cheap and idempotent: PrepareMeshDataAsync early-outs on + /// existing render data and returns the in-flight task when pending. + /// Retail-equivalence: retail loads content synchronously — geometry is + /// never permanently absent; this converges our async pipeline to the + /// same guarantee. + /// + public void EnsureLoaded(ulong id) + { + if (_isUninitialized || _meshManager is null) return; + _meshManager.PrepareMeshDataAsync(id, isSetup: false); + } + /// /// Per-frame drain of the WB pipeline's main-thread work queues. MUST be /// called once per frame from the render thread. Without this, the staged