fix(#192): close login streaming race — gate on a known real position, not session state

User-reported: logging in at a non-Holtburg position sometimes showed
stabs/scenery floating in the wrong place. Root-caused via a threading/
lifecycle trace, not inference: WorldSession transitions to InWorld
immediately after the login handshake (WorldSession.cs:608) — well
before the player's own spawn CreateObject (which carries their real
position) has arrived over the network. The streaming gate's old
condition (`!IsLiveModeWaitingForLogin || liveInWorld`) opened the
instant InWorld fired, letting the background streaming worker
(LandblockStreamer's dedicated Thread) build real landblocks using
whatever _liveCenterX/Y held at that moment — the Holtburg startup
placeholder, not a "not known yet" sentinel. Landblocks that started
building in that window bake their world offset from that placeholder
at build time; if their build was still in flight when the real spawn
arrived and recentered the world (ForceReloadWindow, which only
unloads already-RESIDENT landblocks), they finished and got applied
anyway — stale-positioned geometry landing wherever the guess put it
relative to whatever streamed in afterward with the corrected center.

Confirmed with the user this wasn't "wrong placeholder, need a better
one" — any placeholder racing against the real answer reproduces the
same bug. The fix removes the race instead: StreamingReadinessGate
.ShouldStream requires an explicit liveCenterKnown flag (true only once
the player's own spawn has been processed) in addition to liveInWorld.
Nothing streams in live mode until the real position is confirmed — no
placeholder value is ever acted on. Preserves the #106 gate-3 fix this
gate originally existed for (auto-entry waits for terrain under the
spawn; terrain streaming must not wait for chase mode in turn, or the
two deadlock) since liveCenterKnown becomes true independently of chase
mode, driven purely by the spawn packet's arrival.

The stricter render gate (GameWindow.cs:9596, hides ALL world geometry
until chase mode engages, no relaxation) already provided a partial
safety net and is unchanged — this fix stops the stale geometry from
ever being built, rather than relying on the render gate to hide it
until the reveal.

Core 2680+2skip / App 741+2skip / UI 425 / Net 385 green.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-07-09 15:57:43 +02:00
parent 3dcd53cab7
commit fa9aedca0a
3 changed files with 149 additions and 1 deletions

View file

@ -0,0 +1,51 @@
namespace AcDream.Core.World;
/// <summary>
/// Should the streaming/render pipeline be allowed to run this frame?
///
/// <para>
/// <b>Why this exists (#192, 2026-07-09).</b> Login to a non-Holtburg position
/// sometimes showed stabs/scenery floating in the wrong place. Root cause: the
/// old gate opened as soon as <c>WorldSession</c> reached <c>InWorld</c> — but
/// <c>InWorld</c> fires immediately after the login handshake completes
/// (<c>WorldSession.cs:608</c>), BEFORE the player's own spawn <c>CreateObject</c>
/// (which carries their real position) has even arrived over the network. Any
/// landblock streamed in that window baked its world offset from
/// <c>GameWindow._liveCenterX/Y</c>'s startup placeholder (Holtburg, 0xA9B4) — a
/// real position, not a "not known yet" sentinel — because the streaming worker
/// reads that field fresh at build time with no way to know it's still a guess.
/// That stale-baked geometry still got applied once its build finished, landing
/// wherever the guess put it relative to whatever streamed in afterward using the
/// corrected center.
/// </para>
///
/// <para>
/// The fix is not "pick a better placeholder" — any placeholder racing against
/// the real answer reproduces the same bug. It's gating on whether the real
/// position is actually known yet (<paramref name="liveCenterKnown"/>, set true
/// exactly when the player's own spawn is processed), independent of session
/// state. <paramref name="liveInWorld"/> alone is deliberately no longer
/// sufficient in live mode.
/// </para>
/// </summary>
public static class StreamingReadinessGate
{
/// <param name="liveModeEnabled">Whether a live ACE session is configured at all.
/// False (offline / fly-camera) always streams — there is no real position to
/// wait for, so no race exists.</param>
/// <param name="chaseModeEverEntered">Latches true the first time chase mode
/// engages and stays true for the rest of the session — well past the login
/// race window.</param>
/// <param name="liveInWorld">The live session has completed the login handshake
/// (<c>WorldSession.State.InWorld</c>). Necessary but NOT sufficient on its
/// own — see class remarks.</param>
/// <param name="liveCenterKnown">The player's own spawn <c>CreateObject</c> has
/// been received and processed, so <c>_liveCenterX/Y</c> reflects a real,
/// server-confirmed position rather than the startup placeholder.</param>
public static bool ShouldStream(
bool liveModeEnabled, bool chaseModeEverEntered, bool liveInWorld, bool liveCenterKnown)
{
bool isWaitingForLogin = liveModeEnabled && !chaseModeEverEntered;
return !isWaitingForLogin || (liveInWorld && liveCenterKnown);
}
}