From ef29be59cd6b28e5ac4394bb1c6492259595b576 Mon Sep 17 00:00:00 2001 From: hxbb00 Date: Tue, 23 Aug 2022 16:01:59 +0800 Subject: [PATCH] fix:RTTI head loss (#1675) Co-authored-by: hujin --- src/Generator/Generators/CSharp/CSharpSources.cs | 2 +- src/Runtime/VTables.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpSources.cs b/src/Generator/Generators/CSharp/CSharpSources.cs index a9cfc807..320b9e32 100644 --- a/src/Generator/Generators/CSharp/CSharpSources.cs +++ b/src/Generator/Generators/CSharp/CSharpSources.cs @@ -1832,7 +1832,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat string suffix = (destructorOnly ? "_dtor" : string.Empty) + (tableIndex == 0 ? string.Empty : tableIndex.ToString(CultureInfo.InvariantCulture)); - WriteLine($"{table}[{tableIndex}] = CppSharp.Runtime.VTables.CloneTable(SafeHandles, instance, {vptrOffset}, {entries.Count});"); + WriteLine($"{table}[{tableIndex}] = CppSharp.Runtime.VTables.CloneTable(SafeHandles, instance, {vptrOffset}, {entries.Count}, {offsetRTTI});"); // fill the newly allocated v-table for (var i = 0; i < entries.Count; i++) diff --git a/src/Runtime/VTables.cs b/src/Runtime/VTables.cs index 4bc47916..a7fc1e75 100644 --- a/src/Runtime/VTables.cs +++ b/src/Runtime/VTables.cs @@ -46,15 +46,15 @@ namespace CppSharp.Runtime } } - public unsafe static IntPtr* CloneTable(List cache, IntPtr instance, int offset, int size) + public unsafe static IntPtr* CloneTable(List cache, IntPtr instance, int offset, int size, int offsetRTTI) { - var sizeInBytes = size * sizeof(IntPtr); - var src = ((*(IntPtr*)instance) + offset).ToPointer(); + var sizeInBytes = (size + offsetRTTI) * sizeof(IntPtr); + var src = (((*(IntPtr*)instance) + offset) - offsetRTTI * sizeof(IntPtr)).ToPointer(); var entries = (IntPtr*)Marshal.AllocHGlobal(sizeInBytes); Buffer.MemoryCopy(src, entries, sizeInBytes, sizeInBytes); cache.Add(new SafeUnmanagedMemoryHandle((IntPtr)entries, true)); - return entries; + return entries + offsetRTTI; } } }