From 0801e98823683c2e5feb7e5575b834d44809cb2f Mon Sep 17 00:00:00 2001 From: triton Date: Tue, 5 Nov 2013 00:26:51 +0000 Subject: [PATCH] Fixed generation of C# vtable interop code. Update the vtable generation index in each iteration. --- .../Generators/CSharp/CSharpTextTemplate.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index d76e3a8a..b79a6935 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -1221,15 +1221,20 @@ namespace CppSharp.Generators.CSharp foreach (var vfptr in vftables) { var size = vfptr.Layout.Components.Count; - WriteLine("var vfptr = Marshal.AllocHGlobal({0} * IntPtr.Size);", size); - WriteLine("_NewVTables[{0}] = vfptr;", index++); + WriteLine("var vfptr{0} = Marshal.AllocHGlobal({1} * IntPtr.Size);", + index, size); + WriteLine("_NewVTables[{0}] = vfptr{0};", index); var entryIndex = 0; foreach (var entry in vfptr.Layout.Components) { - var offsetInBytes = VTables.GetVTableComponentIndex(@class, entry)*IntPtr.Size; - WriteLine("*(IntPtr*)(vfptr + {0}) = _Thunks[{1}];", offsetInBytes, entryIndex++); + var offsetInBytes = VTables.GetVTableComponentIndex(@class, entry) + * IntPtr.Size; + WriteLine("*(IntPtr*)(vfptr{0} + {1}) = _Thunks[{2}];", index, + offsetInBytes, entryIndex++); } + + index++; } WriteCloseBraceIndent(); @@ -1404,8 +1409,7 @@ namespace CppSharp.Generators.CSharp PushBlock(CSharpBlockKind.InternalsClassField); WriteLine("[FieldOffset({0})]", info.VFPtrFullOffset); - WriteLine("public global::System.IntPtr vfptr{0};", - info.VFPtrFullOffset, index++); + WriteLine("public global::System.IntPtr vfptr{0};", index++); PopBlock(NewLineKind.BeforeNextBlock); }