Browse Source

Fixed a crash when setting up v-tables.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/94/head
Dimitar Dobrev 12 years ago
parent
commit
9deaa403bc
  1. 14
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  2. 1
      tests/CSharpTemp/CSharpTemp.cs

14
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -1245,11 +1245,21 @@ namespace CppSharp.Generators.CSharp
NewLine(); NewLine();
} }
private void GenerateVTableClassSetupCall(Class @class) private void GenerateVTableClassSetupCall(Class @class, bool addPointerGuard = false)
{ {
var entries = GetVTableMethodEntries(@class); var entries = GetVTableMethodEntries(@class);
if (Options.GenerateVirtualTables && @class.IsDynamic && entries.Count != 0) if (Options.GenerateVirtualTables && @class.IsDynamic && entries.Count != 0)
{
// called from internal ctors which may have been passed an IntPtr.Zero
if (addPointerGuard)
{
WriteLine("if ({0} != global::System.IntPtr.Zero)", Helpers.InstanceIdentifier);
PushIndent();
}
WriteLine("SetupVTables({0});", Generator.GeneratedIdentifier("Instance")); WriteLine("SetupVTables({0});", Generator.GeneratedIdentifier("Instance"));
if (addPointerGuard)
PopIndent();
}
} }
private void GenerateVTableManagedCall(Method method) private void GenerateVTableManagedCall(Method method)
@ -1613,7 +1623,7 @@ namespace CppSharp.Generators.CSharp
if (ShouldGenerateClassNativeField(@class)) if (ShouldGenerateClassNativeField(@class))
{ {
WriteLine("{0} = native;", Helpers.InstanceIdentifier); WriteLine("{0} = native;", Helpers.InstanceIdentifier);
GenerateVTableClassSetupCall(@class); GenerateVTableClassSetupCall(@class, true);
} }
} }
else else

1
tests/CSharpTemp/CSharpTemp.cs

@ -14,6 +14,7 @@ namespace CppSharp.Tests
{ {
driver.Options.GenerateInterfacesForMultipleInheritance = true; driver.Options.GenerateInterfacesForMultipleInheritance = true;
driver.Options.GenerateProperties = true; driver.Options.GenerateProperties = true;
driver.Options.GenerateVirtualTables = true;
} }
public static void Main(string[] args) public static void Main(string[] args)

Loading…
Cancel
Save