aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
-rw-r--r--tests/Program.cs18
-rw-r--r--vk.generator/Program.cs44
2 files changed, 29 insertions, 33 deletions
diff --git a/tests/Program.cs b/tests/Program.cs
index 5900aeb..0a3d501 100644
--- a/tests/Program.cs
+++ b/tests/Program.cs
@@ -15,18 +15,15 @@ namespace tests
{
VkInstance instance;
- VkInstanceCreateInfo ci = VkInstanceCreateInfo.New();
- VkApplicationInfo ai = VkApplicationInfo.New();
- ai.apiVersion = new Version (1,0,0);
- ai.applicationVersion = new Version (1,0,0);
- ai.pApplicationName = "new application name";
- ai.pEngineName = "new engine name";
+ using (VkApplicationInfo ai = new VkApplicationInfo(
+ new Version (1,0,0),
+ new Version (1,0,0),
+ new Version (1,2,0)) {pApplicationName = "new application name"}){
- VkClearColorValue clear = new VkClearColorValue(255,0,0);
- clear.floats[2] = 210;
-
- using (PinnedObjects pi = new PinnedObjects()) {
+ VkClearColorValue clear = new VkClearColorValue(255,0,0);
+ clear.floats[2] = 210;
+ VkInstanceCreateInfo ci = VkInstanceCreateInfo.New();
ci.pApplicationInfo = ai;
VkResult res = vkCreateInstance (ref ci, IntPtr.Zero, out instance);
@@ -36,6 +33,7 @@ namespace tests
}else
Console.WriteLine ($"Success: {res}");
+ ci.Dispose();
}
vkDestroyInstance (instance, IntPtr.Zero);
diff --git a/vk.generator/Program.cs b/vk.generator/Program.cs
index dbd3263..8dd0bcf 100644
--- a/vk.generator/Program.cs
+++ b/vk.generator/Program.cs
@@ -792,22 +792,21 @@ namespace vk.generator {
}
}
//check if ptrProxies are used => if yes must implement IDisposable
- static string[] getStructurePtrProxies (StructDef sd) {
- List<string> proxies = new List<string>();
+ static void getStructurePtrProxies (StructDef sd, out IEnumerable<string> proxies, out IEnumerable<string> utf8StringPointers) {
+ List<string> _proxies = new List<string>();
+ List<string> _utf8StringPointers = new List<string>();
foreach (MemberDef mb in sd.members) {
if (!mb.paramDef.tryGetTypeDef (out TypeDef td))
throw new Exception($"type not found {mb.paramDef}");
if (mb.paramDef.IndirectionLevel == 1){
if (mb.paramDef.Name == "char")
- continue;
- else if (mb.paramDef.Name != "void" && td.CSName != "IntPtr" && td.CSName != "UIntPtr") {
- /*if (td == null || (td.category == TypeCategories.basetype && td.baseType == null))
- continue;*/
- proxies.Add (mb.Name);
- }
+ _utf8StringPointers.Add (mb.Name);
+ else if (mb.paramDef.Name != "void" && td.CSName != "IntPtr" && td.CSName != "UIntPtr")
+ _proxies.Add (mb.Name);
}
}
- return (proxies.Count == 0) ? null : proxies.ToArray();
+ proxies = _proxies;
+ utf8StringPointers = _utf8StringPointers;
}
static void write_structurePointerProxy_member (IndentedTextWriter tw, StructDef sd, MemberDef mb) {
if (!mb.paramDef.tryGetTypeDef (out TypeDef td))
@@ -868,9 +867,9 @@ namespace vk.generator {
else
tw.WriteLine ($"[StructLayout(LayoutKind.Sequential)]");
- string[] ptrProxies = getStructurePtrProxies (sd);
- List<string> utf8StringPointers = new List<string>();
- if (ptrProxies == null)
+ getStructurePtrProxies (sd, out IEnumerable<string> ptrProxies, out IEnumerable<string> utf8StringPointers);
+
+ if (ptrProxies.Count() == 0 && utf8StringPointers.Count() == 0)
tw.WriteLine ($"public partial struct {sd.Name} {{");
else
tw.WriteLine ($"public partial struct {sd.Name} : IDisposable {{");
@@ -890,10 +889,9 @@ namespace vk.generator {
throw new Exception($"type not found {mb.paramDef}");
if (mb.paramDef.IndirectionLevel == 1){
- if (mb.paramDef.Name == "char") {
+ if (mb.paramDef.Name == "char")
tw.WriteLine ($"public Utf8StringPointer {mb.Name};");
- utf8StringPointers.Add (mb.Name);
- } else if (mb.paramDef.Name != "void" && td.CSName != "IntPtr" && td.CSName != "UIntPtr")
+ else if (mb.paramDef.Name != "void" && td.CSName != "IntPtr" && td.CSName != "UIntPtr")
write_structurePointerProxy_member (tw, sd, mb);
else
tw.WriteLine ($"public IntPtr {mb.Name};");
@@ -1058,17 +1056,17 @@ namespace vk.generator {
//========
}
- if (ptrProxies != null || utf8StringPointers.Count > 0) {
+ if (ptrProxies.Count() > 0 || utf8StringPointers.Count() > 0) {
tw.WriteLine ($"public void Dispose() {{");
tw.Indent++;
- if (ptrProxies != null) {
- foreach (string proxy in ptrProxies) {
- tw.WriteLine ($"if (_{proxy} != IntPtr.Zero)");
- tw.Indent++;
- tw.WriteLine ($"_{proxy}.Unpin ();");
- tw.Indent--;
- }
+
+ foreach (string proxy in ptrProxies) {
+ tw.WriteLine ($"if (_{proxy} != IntPtr.Zero)");
+ tw.Indent++;
+ tw.WriteLine ($"_{proxy}.Unpin ();");
+ tw.Indent--;
}
+
foreach (string proxy in utf8StringPointers)
tw.WriteLine ($"{proxy}.Dispose ();");