fix(plugins): popped-out embed surfaces no longer crash the client

See Changelog/2026-10-11-popout-embed-crash.md.
This commit is contained in:
BlankenshipG 2026-10-12 00:32:18 -04:00
commit 2066033759
3 changed files with 86 additions and 7 deletions

View file

@ -0,0 +1,43 @@
# Fix: a popped-out Mini Remote or Guardian crashed the client
Follows the menu changes (`2026-10-11-character-and-server-menus.md`). Pairs with the RynthSuite
change that draws `:popout` surfaces in the current context.
## The crash
Four crashes on 2026-10-11 had the same stack:
```
EndSceneDetour -> EngineFrameController.OnEndScene -> ImGuiPopOuts.RenderAll
-> ImGuiPanelHost.DrawPopped -> MiniRemoteFace.Draw -> DrawRynthAi
-> PluginManager.RenderEmbed -> (RynthAi) -> access violation in coreclr
```
- `ImGuiPopOuts` gives every popped-out panel its own ImGui context.
- `PluginManager.RenderEmbed` called RynthAi from inside it. RynthAi then switched
to the main context, which isn't mid-frame there, and faulted.
- An access violation isn't an exception `RenderEmbed`'s try/catch can stop, so the client died.
- The "MAIN THREAD HANG DETECTED" line before each exit was the runtime writing the 700 MB crash
dump.
## Fix
- `PluginManager.RenderEmbed` checks the current ImGui context. When it isn't the one plugins
were given (a pop-out), the surface goes out as `name:popout`.
- RynthAi with the matching RynthSuite change draws it in the current context.
- Older plugins don't know the name and decline. The Mini Remote then shows the engine's own
slot grid, and the Guardian panel its "not ready" state, instead of crashing.
- This covers every embedded surface: the Mini Remote window, the RynthAi dashboard's Mini Remote
drawer, and the Guardian panel.
- It also returns "not ready" when no ImGui context is current.
## Files
- `src/RynthCore.Engine/Plugins/PluginManager.cs`: `RenderEmbed` (context check and the
`:popout` name), with the export call moved to `RenderEmbedCore`.
- `src/RynthCore.Engine/ImGui/Panels/MiniRemoteFace.cs`: header note on the fallback.
## Testing
- The engine builds in Release, and ItemHudTests pass.
- Not yet checked in game: the popped-out Mini Remote, with a current and with an older RynthAi.

View file

@ -12,8 +12,9 @@
// a resize by hand holds until then. While this window shows it, RynthAi keeps
// its own floating copy hidden, so there is one Mini Remote, not two.
//
// Without RynthAi (not loaded, too old for the surface, not logged in yet, or
// its embed failed) it is the engine's own grid (an idea from Silentkelpie's
// Without RynthAi (not loaded, too old for the surface, not logged in yet,
// popped out with a RynthAi older than 0.5.38, which can't draw in a pop-out's
// context, or its embed failed) it is the engine's own grid (an idea from Silentkelpie's
// rynth PR #1, done as an engine face):
// slots the item's icon and carried count; an empty slot shows +
// click uses the slot's item (the same object if still carried, else a

View file

@ -1249,21 +1249,56 @@ internal static partial class PluginManager
/// <summary>RenderEmbed results.</summary>
internal const int EmbedDrawn = 1, EmbedNotReady = 0, EmbedNoPlugin = -1, EmbedFailed = -2;
/// <summary>
/// Appended to an embed surface's name when the caller draws in another ImGui context than
/// the one plugins were given (a popped-out panel's own context). Only a plugin that knows
/// the suffix draws then, into the current context; an older one switches to the main
/// context, which is not mid-frame there, and faults inside cimgui (an access violation no
/// try/catch stops: 2026-10-11, the popped-out Mini Remote), so it must see a surface name
/// it doesn't know and decline.
/// </summary>
private static ReadOnlySpan<byte> PopOutSurfaceSuffix => ":popout"u8;
/// <summary>
/// Lets the plugin named <paramref name="pluginName"/> (display name contains it) draw the
/// surface <paramref name="surfaceUtf8"/> (NUL-terminated) into the current ImGui window,
/// through its optional RynthPluginRenderEmbed export. The caller has begun a child of
/// <paramref name="size"/> in the main ImGui context; the plugin draws only inside it and
/// reports the content size it wants in <paramref name="want"/> (zero when it didn't say).
/// <paramref name="size"/>; the plugin draws only inside it and reports the content size it
/// wants in <paramref name="want"/> (zero when it didn't say). In a context other than the
/// plugins' (a pop-out), the surface goes out as "name:popout" (see
/// <see cref="PopOutSurfaceSuffix"/>).
/// Render thread only. Returns <see cref="EmbedDrawn"/>, <see cref="EmbedNotReady"/> (the
/// plugin isn't ready: before login, no ImGui context), <see cref="EmbedNoPlugin"/> (not
/// loaded, or too old to have the export) or <see cref="EmbedFailed"/> (it threw: the export
/// is switched off for this session; the plugin keeps running).
/// plugin isn't ready: before login, no ImGui context, or too old to draw in a pop-out),
/// <see cref="EmbedNoPlugin"/> (not loaded, or too old to have the export) or
/// <see cref="EmbedFailed"/> (it threw: the export is switched off for this session; the
/// plugin keeps running).
/// </summary>
internal static unsafe int RenderEmbed(string pluginName, ReadOnlySpan<byte> surfaceUtf8, System.Numerics.Vector2 size, out System.Numerics.Vector2 want)
{
want = System.Numerics.Vector2.Zero;
if (!_loginCompleteObserved) return EmbedNotReady; // same not-in-world guard as RenderAll
IntPtr current = ImGuiNET.ImGui.GetCurrentContext();
if (current == IntPtr.Zero) return EmbedNotReady;
if (current != _api.ImGuiContext)
{
// "name\0" -> "name:popout\0" on the stack; surface names are a few bytes.
int nameLen = surfaceUtf8.IndexOf((byte)0);
if (nameLen < 0) nameLen = surfaceUtf8.Length;
int total = nameLen + PopOutSurfaceSuffix.Length + 1;
if (total > 128) return EmbedNotReady;
Span<byte> popOut = stackalloc byte[total];
surfaceUtf8[..nameLen].CopyTo(popOut);
PopOutSurfaceSuffix.CopyTo(popOut[nameLen..]);
popOut[^1] = 0;
return RenderEmbedCore(pluginName, popOut, size, out want);
}
return RenderEmbedCore(pluginName, surfaceUtf8, size, out want);
}
/// <summary>The export call behind <see cref="RenderEmbed"/>, with the surface name already final.</summary>
private static unsafe int RenderEmbedCore(string pluginName, ReadOnlySpan<byte> surfaceUtf8, System.Numerics.Vector2 size, out System.Numerics.Vector2 want)
{
want = System.Numerics.Vector2.Zero;
LoadedPlugin[] plugins = System.Threading.Volatile.Read(ref _pluginsRenderSnapshot);
for (int i = 0; i < plugins.Length; i++)
{