Browse Source

fix:RTTI head loss (#1675)

Co-authored-by: hujin <hj@mapgis.com>
pull/1670/head
hxbb00 3 years ago committed by GitHub
parent
commit
ef29be59cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/Generator/Generators/CSharp/CSharpSources.cs
  2. 8
      src/Runtime/VTables.cs

2
src/Generator/Generators/CSharp/CSharpSources.cs

@ -1832,7 +1832,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
string suffix = (destructorOnly ? "_dtor" : string.Empty) + string suffix = (destructorOnly ? "_dtor" : string.Empty) +
(tableIndex == 0 ? string.Empty : tableIndex.ToString(CultureInfo.InvariantCulture)); (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 // fill the newly allocated v-table
for (var i = 0; i < entries.Count; i++) for (var i = 0; i < entries.Count; i++)

8
src/Runtime/VTables.cs

@ -46,15 +46,15 @@ namespace CppSharp.Runtime
} }
} }
public unsafe static IntPtr* CloneTable(List<SafeUnmanagedMemoryHandle> cache, IntPtr instance, int offset, int size) public unsafe static IntPtr* CloneTable(List<SafeUnmanagedMemoryHandle> cache, IntPtr instance, int offset, int size, int offsetRTTI)
{ {
var sizeInBytes = size * sizeof(IntPtr); var sizeInBytes = (size + offsetRTTI) * sizeof(IntPtr);
var src = ((*(IntPtr*)instance) + offset).ToPointer(); var src = (((*(IntPtr*)instance) + offset) - offsetRTTI * sizeof(IntPtr)).ToPointer();
var entries = (IntPtr*)Marshal.AllocHGlobal(sizeInBytes); var entries = (IntPtr*)Marshal.AllocHGlobal(sizeInBytes);
Buffer.MemoryCopy(src, entries, sizeInBytes, sizeInBytes); Buffer.MemoryCopy(src, entries, sizeInBytes, sizeInBytes);
cache.Add(new SafeUnmanagedMemoryHandle((IntPtr)entries, true)); cache.Add(new SafeUnmanagedMemoryHandle((IntPtr)entries, true));
return entries; return entries + offsetRTTI;
} }
} }
} }

Loading…
Cancel
Save