fix(engine): destroy panel windows on their owner thread; hold login pop-out until game window is hooked
LayeredWindow.Dispose now destroys inline when the caller owns the HWND, else posts WM_RYNTH_SELF_DESTROY to the panel itself. Floating-panel restore at login waits for Win32Backend.CanRunOnGameThread so the HWND is created on AC's game thread. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
c6e44ee348
commit
6908c64807
4 changed files with 165 additions and 87 deletions
|
|
@ -70,13 +70,9 @@ internal static unsafe class Win32Backend
|
|||
/// HWNDs drop WM_LBUTTONDOWN on Win11 in some focus states).</summary>
|
||||
public const uint WM_RYNTH_RUN_ACTION = 0x8002;
|
||||
|
||||
/// <summary>UI deep-dive finding P0-1 belt-and-braces (2026-07-02):
|
||||
/// posted (not sent) by LayeredWindow.Dispose to destroy an HWND on the
|
||||
/// game thread without blocking the calling thread — DestroyWindow must
|
||||
/// run on the owning thread, but the caller (often the Avalonia UI
|
||||
/// thread, e.g. redocking a panel) doesn't need to wait for it to
|
||||
/// finish. wParam carries the HWND to destroy.</summary>
|
||||
public const uint WM_RYNTH_DESTROY_HWND = 0x8003;
|
||||
// 0x8003 was WM_RYNTH_DESTROY_HWND (destroy a panel via the game window).
|
||||
// Retired: LayeredWindow now posts WM_RYNTH_SELF_DESTROY (0x8005) to the
|
||||
// panel itself so it is destroyed on its real owner thread. Don't reuse 0x8003.
|
||||
|
||||
/// <summary>Destroys floating-panel HWNDs on the game thread (their owner).
|
||||
/// wParam != 0 includes this engine load's own panels (sent synchronously by
|
||||
|
|
@ -364,36 +360,12 @@ internal static unsafe class Win32Backend
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// UI deep-dive finding P0-1 (2026-07-02): posts (does not block on) a
|
||||
/// DestroyWindow for <paramref name="hwnd"/> onto the game thread.
|
||||
/// DestroyWindow must run on the HWND's owning thread, but unlike
|
||||
/// RunOnGameThread this never needs the caller to observe a result — so
|
||||
/// it uses a dedicated PostMessage instead of the shared
|
||||
/// RunOnGameThread action slot, avoiding any risk of blocking the
|
||||
/// caller (e.g. LayeredWindow.Dispose called from the Avalonia UI
|
||||
/// thread while redocking a panel) on the game thread's WndProc.
|
||||
/// True once the game window is known AND its WndProc is subclassed, i.e.
|
||||
/// <see cref="RunOnGameThread{T}"/> can actually deliver work to AC's main
|
||||
/// thread. Knowing the HWND alone is not enough: without the subclass,
|
||||
/// WM_RYNTH_RUN_ACTION reaches AC's own WndProc, which ignores it.
|
||||
/// </summary>
|
||||
public static void PostDestroyWindow(IntPtr hwnd)
|
||||
{
|
||||
if (hwnd == IntPtr.Zero) return;
|
||||
if (_gameHwnd == IntPtr.Zero)
|
||||
{
|
||||
// No game thread to marshal to (e.g. very early/late in
|
||||
// lifecycle) — best-effort inline as LayeredWindow.Dispose's own
|
||||
// fallback already does for the RunOnGameThread-unavailable case.
|
||||
DestroyWindow(hwnd);
|
||||
return;
|
||||
}
|
||||
|
||||
GetWindowThreadProcessId(_gameHwnd, out uint gameThreadId);
|
||||
if (gameThreadId == GetCurrentThreadId())
|
||||
{
|
||||
DestroyWindow(hwnd);
|
||||
return;
|
||||
}
|
||||
|
||||
PostMessage(_gameHwnd, WM_RYNTH_DESTROY_HWND, hwnd, IntPtr.Zero);
|
||||
}
|
||||
public static bool CanRunOnGameThread => _initialized && _gameHwnd != IntPtr.Zero;
|
||||
|
||||
/// <summary>Deactivates chat capture. The game HWND retains focus throughout so no
|
||||
/// Win32 focus transfer is needed.</summary>
|
||||
|
|
@ -532,10 +504,11 @@ internal static unsafe class Win32Backend
|
|||
if (!_initialized) return;
|
||||
|
||||
// Destroy floating panels while our hook can still run on the game
|
||||
// thread. LayeredWindow.Dispose only POSTS its destroy, and the game
|
||||
// thread usually hasn't reached that post by the time we unhook below —
|
||||
// AC's own WndProc then drops it and the panel outlives this engine
|
||||
// load, frozen and unclickable (duplicate RynthAi dashboard after RL).
|
||||
// thread. LayeredWindow.Dispose posts its destroy to the panel itself
|
||||
// (handled by the panel's own WndProc, which survives this unhook), but
|
||||
// any panel never disposed would outlive this engine load, frozen and
|
||||
// unclickable (duplicate RynthAi dashboard after RL) — this sweep is the
|
||||
// synchronous backstop for those.
|
||||
IntPtr swept = SendMessageTimeout(_gameHwnd, WM_RYNTH_SWEEP_PANELS, new IntPtr(1), IntPtr.Zero,
|
||||
SMTO_NORMAL, 2000, out _);
|
||||
if (swept == IntPtr.Zero)
|
||||
|
|
@ -706,19 +679,6 @@ internal static unsafe class Win32Backend
|
|||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
if (msg == WM_RYNTH_DESTROY_HWND)
|
||||
{
|
||||
IntPtr target = wParam;
|
||||
try
|
||||
{
|
||||
bool destroyed = DestroyWindow(target);
|
||||
int err = destroyed ? 0 : Marshal.GetLastWin32Error();
|
||||
RynthLog.Info($"Win32Backend: WM_RYNTH_DESTROY_HWND DestroyWindow(0x{target.ToInt64():X}) = {destroyed} err={err}.");
|
||||
}
|
||||
catch (Exception ex) { RynthLog.Info($"Win32Backend: WM_RYNTH_DESTROY_HWND threw {ex.GetType().Name}: {ex.Message}"); }
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
if (msg == WM_RYNTH_SWEEP_PANELS)
|
||||
{
|
||||
try { UI.LayeredWindow.DestroyThreadPanelWindows(includeThisGeneration: wParam != IntPtr.Zero); }
|
||||
|
|
|
|||
Loading…
Reference in a new issue