fix(engine): plugin sections in pop-outs draw in the pop-out's ImGui context (2026.10.20.4)
Managed plugins loaded a second cimgui.dll whose current context stayed the main one; a section drawn in a popped-out Mini Remote then faulted in igGetCursorPosY and the runtime aborted the client (RynthDreamWeave's server card, SK). Managed plugins now bind cimgui to the engine's module, and pop-out plugin calls set the pop-out context in any second cimgui too. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
cbd18a6880
commit
bbf8e7154b
4 changed files with 137 additions and 1 deletions
|
|
@ -0,0 +1,46 @@
|
|||
# Engine: a plugin section in a popped-out window no longer kills the client (2026-10-20)
|
||||
|
||||
RynthCore engine 2026.10.20.4. Previous release: 2026.10.19.3 (the live engine).
|
||||
|
||||
## The crash (SK on DreamWeave, 2026-10-19 20:15:45 and 20:19:17)
|
||||
|
||||
Opening the "DreamWeave server (RynthDreamWeave)" entry in a popped-out Mini Remote froze the
|
||||
client and closed it about 20 seconds later. The same thing happened on a second DreamWeave client
|
||||
(pid 43516). The engine logged a main-thread hang; its CLR dump shows what actually happened:
|
||||
|
||||
- AC's main thread (0x7894, the one that draws the pop-outs) holds a
|
||||
`System.ExecutionEngineException`, the runtime's fatal error, in
|
||||
`ServerPackPlugin.RenderEmbeddedCard` -> `ImGuiNative.igGetCursorPosY()`, called from the
|
||||
popped-out Mini Remote's frame. The "hang" was the runtime dying: writing the dump, then
|
||||
terminating the client.
|
||||
- That RynthDreamWeave is rynth's managed build (API v88): it loads into its own
|
||||
AssemblyLoadContext with its own copy of ImGui.NET. The engine's DLL resolver only covers its own
|
||||
ImGui.NET, so the plugin's copy loaded a second `cimgui.dll`: a second ImGui with its own
|
||||
"current context". The dump has both modules, `RynthCore.cimgui.dll` (the engine's) and
|
||||
`Runtime\cimgui.dll`.
|
||||
- A pop-out draws in a context of its own, made current only in the engine's cimgui. The plugin
|
||||
asked its own copy for the current context, got the main one (not in a frame then), and its first
|
||||
call ran against a window that wasn't there: an access violation in native code, which no
|
||||
try/catch stops.
|
||||
|
||||
The docked Mini Remote worked by luck: there the main context is the one in a frame. Every
|
||||
managed plugin loaded the same way (RynthLua, RynthNav, RynthTracker, RynthVision, RynthInventory,
|
||||
RynthSort, RynthNet, RynthThreads and the server plugins), so any of their sections in a pop-out
|
||||
could do the same, on any client.
|
||||
|
||||
### Changed
|
||||
|
||||
- **Managed plugins share the engine's ImGui.** A managed plugin's load context resolves `cimgui`
|
||||
/ `cimgui.dll` to the engine's own module (`ManagedPlugins.PluginLoadContext.LoadUnmanagedDll`):
|
||||
one ImGui, one current context, so a pop-out's context is the one the plugin draws in.
|
||||
- **Pop-outs set the context in a second cimgui too** (`Plugins/StrayImGuiContext.cs`). When a
|
||||
`cimgui.dll` that isn't the engine's is loaded (a NativeAOT plugin that doesn't bind its ImGui.NET
|
||||
to the engine's module), a plugin call made inside a pop-out
|
||||
(`PluginManager.RenderEmbed`, ":popout" surfaces: Mini Remote sections, Guardian, RynthAi panels)
|
||||
first makes the pop-out's context current in that copy, and puts the copy's own context back
|
||||
afterwards. Logged once: `a second cimgui.dll is loaded ...`.
|
||||
|
||||
## Tests
|
||||
|
||||
- Engine builds clean. The fix is native interop with the game's ImGui, so it was checked against
|
||||
the crash dump rather than a unit test: the faulting frame is exactly the call path changed.
|
||||
|
|
@ -196,6 +196,15 @@ internal static class ManagedPlugins
|
|||
|
||||
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
|
||||
{
|
||||
// ImGui.NET's "cimgui": the engine's own module, so the plugin draws in the engine's
|
||||
// ImGui and its current context (a pop-out's included). Its own copy of ImGui.NET used
|
||||
// to load a second cimgui.dll whose current context stayed the main one; drawing a
|
||||
// section in a popped-out Mini Remote then ran against a context outside its frame and
|
||||
// faulted in cimgui, killing the client (RynthDreamWeave's server card, 2026-10-19).
|
||||
if (EntryPoint.ImGuiNativeHandle != IntPtr.Zero
|
||||
&& (unmanagedDllName.Equals("cimgui", StringComparison.OrdinalIgnoreCase)
|
||||
|| unmanagedDllName.Equals("cimgui.dll", StringComparison.OrdinalIgnoreCase)))
|
||||
return EntryPoint.ImGuiNativeHandle;
|
||||
string candidate = Path.Combine(_dir, unmanagedDllName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)
|
||||
? unmanagedDllName
|
||||
: unmanagedDllName + ".dll");
|
||||
|
|
|
|||
|
|
@ -1354,7 +1354,10 @@ internal static partial class PluginManager
|
|||
surfaceUtf8[..nameLen].CopyTo(popOut);
|
||||
PopOutSurfaceSuffix.CopyTo(popOut[nameLen..]);
|
||||
popOut[^1] = 0;
|
||||
return RenderEmbedCore(pluginName, popOut, size, out want);
|
||||
// A plugin on a second cimgui copy must see the pop-out's context there too (StrayImGuiContext).
|
||||
StrayImGuiContext.Scope stray = StrayImGuiContext.Enter(current);
|
||||
try { return RenderEmbedCore(pluginName, popOut, size, out want); }
|
||||
finally { StrayImGuiContext.Restore(stray); }
|
||||
}
|
||||
return RenderEmbedCore(pluginName, surfaceUtf8, size, out want);
|
||||
}
|
||||
|
|
|
|||
78
src/RynthCore.Engine/Plugins/StrayImGuiContext.cs
Normal file
78
src/RynthCore.Engine/Plugins/StrayImGuiContext.cs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
// ============================================================================
|
||||
// RynthCore.Engine - Plugins/StrayImGuiContext.cs
|
||||
//
|
||||
// A plugin whose ImGui.NET isn't bound to the engine's cimgui (RynthCore.cimgui.dll) calls a
|
||||
// second copy, cimgui.dll, with an ImGui of its own: its own "current context". Plugins set that
|
||||
// to the engine's context before drawing and read it back with GetCurrentContext, which works in
|
||||
// the main frame. A popped-out window draws in a context of its own (ImGuiPopOuts), and the
|
||||
// engine makes it current only in ITS cimgui: the stray copy still names the main context, which
|
||||
// is not in a frame then, and the plugin's first call (igGetCursorPosY) faulted on its missing
|
||||
// window. That is an access violation in native code, which no try/catch stops: the runtime
|
||||
// aborted the client (RynthDreamWeave's server card in a popped-out Mini Remote, 2026-10-19).
|
||||
//
|
||||
// So around a plugin call made inside a pop-out, the pop-out's context is made current in the
|
||||
// stray copy too, and the copy's own current context is put back afterwards. Nothing is done
|
||||
// when no second cimgui is loaded (every plugin bound to the engine's). Render thread only.
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RynthCore.Engine.Plugins;
|
||||
|
||||
internal static unsafe class StrayImGuiContext
|
||||
{
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, EntryPoint = "GetModuleHandleW")]
|
||||
private static extern IntPtr GetModuleHandleW(string name);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, EntryPoint = "GetProcAddress")]
|
||||
private static extern IntPtr GetProcAddress(IntPtr module, string name);
|
||||
|
||||
// The stray module these pointers belong to (the module can load after the first pop-out frame).
|
||||
private static IntPtr _module;
|
||||
private static delegate* unmanaged[Cdecl]<IntPtr> _get;
|
||||
private static delegate* unmanaged[Cdecl]<IntPtr, void> _set;
|
||||
|
||||
/// <summary>What <see cref="Enter"/> changed, for <see cref="Restore"/>.</summary>
|
||||
public readonly struct Scope
|
||||
{
|
||||
public readonly bool Entered;
|
||||
public readonly IntPtr Previous;
|
||||
public Scope(bool entered, IntPtr previous) { Entered = entered; Previous = previous; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes <paramref name="context"/> current in the stray cimgui, if one is loaded; the scope
|
||||
/// says what to put back (nothing when there is no stray copy).
|
||||
/// </summary>
|
||||
public static Scope Enter(IntPtr context)
|
||||
{
|
||||
if (context == IntPtr.Zero || !Resolve()) return default;
|
||||
IntPtr previous = _get();
|
||||
_set(context);
|
||||
return new Scope(true, previous);
|
||||
}
|
||||
|
||||
/// <summary>Puts back the stray copy's own current context (zero included: a pop-out's must not linger there).</summary>
|
||||
public static void Restore(Scope scope)
|
||||
{
|
||||
if (!scope.Entered || _set == null) return;
|
||||
_set(scope.Previous);
|
||||
}
|
||||
|
||||
/// <summary>True with the stray copy's two calls ready: a cimgui.dll loaded that isn't the engine's.</summary>
|
||||
private static bool Resolve()
|
||||
{
|
||||
IntPtr module = GetModuleHandleW("cimgui.dll");
|
||||
if (module == IntPtr.Zero || module == EntryPoint.ImGuiNativeHandle) return false;
|
||||
if (module == _module && _get != null && _set != null) return true;
|
||||
IntPtr get = GetProcAddress(module, "igGetCurrentContext");
|
||||
IntPtr set = GetProcAddress(module, "igSetCurrentContext");
|
||||
if (get == IntPtr.Zero || set == IntPtr.Zero) return false;
|
||||
_get = (delegate* unmanaged[Cdecl]<IntPtr>)get;
|
||||
_set = (delegate* unmanaged[Cdecl]<IntPtr, void>)set;
|
||||
_module = module;
|
||||
RynthLog.Plugin($"PluginManager: a second cimgui.dll is loaded (0x{module:X8}); popped-out plugin surfaces get the pop-out's context in it too.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue