Skip to content

Commit ef29be5

Browse files
hxbb00hujin
andauthored
fix:RTTI head loss (#1675)
Co-authored-by: hujin <[email protected]>
1 parent ce9e63f commit ef29be5

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Generator/Generators/CSharp/CSharpSources.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@ private void AllocateNewVTableEntries(IList<VTableComponent> entries,
18321832
string suffix = (destructorOnly ? "_dtor" : string.Empty) +
18331833
(tableIndex == 0 ? string.Empty : tableIndex.ToString(CultureInfo.InvariantCulture));
18341834

1835-
WriteLine($"{table}[{tableIndex}] = CppSharp.Runtime.VTables.CloneTable(SafeHandles, instance, {vptrOffset}, {entries.Count});");
1835+
WriteLine($"{table}[{tableIndex}] = CppSharp.Runtime.VTables.CloneTable(SafeHandles, instance, {vptrOffset}, {entries.Count}, {offsetRTTI});");
18361836

18371837
// fill the newly allocated v-table
18381838
for (var i = 0; i < entries.Count; i++)

src/Runtime/VTables.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ public T GetMethodDelegate<T>(short table, int slot, short specialiation = 0) wh
4646
}
4747
}
4848

49-
public unsafe static IntPtr* CloneTable(List<SafeUnmanagedMemoryHandle> cache, IntPtr instance, int offset, int size)
49+
public unsafe static IntPtr* CloneTable(List<SafeUnmanagedMemoryHandle> cache, IntPtr instance, int offset, int size, int offsetRTTI)
5050
{
51-
var sizeInBytes = size * sizeof(IntPtr);
52-
var src = ((*(IntPtr*)instance) + offset).ToPointer();
51+
var sizeInBytes = (size + offsetRTTI) * sizeof(IntPtr);
52+
var src = (((*(IntPtr*)instance) + offset) - offsetRTTI * sizeof(IntPtr)).ToPointer();
5353
var entries = (IntPtr*)Marshal.AllocHGlobal(sizeInBytes);
5454

5555
Buffer.MemoryCopy(src, entries, sizeInBytes, sizeInBytes);
5656
cache.Add(new SafeUnmanagedMemoryHandle((IntPtr)entries, true));
57-
return entries;
57+
return entries + offsetRTTI;
5858
}
5959
}
6060
}

0 commit comments

Comments
 (0)