diff --git a/addons/imgui-godot/ImGuiGodot/Internal/Util.cs b/addons/imgui-godot/ImGuiGodot/Internal/Util.cs index 690069e..b588876 100644 --- a/addons/imgui-godot/ImGuiGodot/Internal/Util.cs +++ b/addons/imgui-godot/ImGuiGodot/Internal/Util.cs @@ -1,13 +1,20 @@ -#if GODOT_PC using Godot; using System; +#if GODOT_PC using System.Reflection; using System.Reflection.Emit; +#else +using System.Diagnostics; +using System.Runtime.InteropServices; +#endif namespace ImGuiGodot.Internal; internal static class Util { +#if GODOT_PC + // this is ~15x faster, so keep it for non-AOT platforms + public static readonly Func ConstructRid; static Util() @@ -23,5 +30,16 @@ static Util() il.Emit(OpCodes.Ret); ConstructRid = dm.CreateDelegate>(); } -} +#else + public static Rid ConstructRid(ulong id) + { + Debug.Assert(Marshal.SizeOf() == sizeof(ulong)); + nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf()); + byte[] bytes = BitConverter.GetBytes(id); + Marshal.Copy(bytes, 0, ptr, bytes.Length); + Rid rv = Marshal.PtrToStructure(ptr); + Marshal.FreeHGlobal(ptr); + return rv; + } #endif +}