Commits

Tobias Bohnen committed ff9fb00

* ensure last value of args array is null

Comments (0)

Files changed (4)

 
         public Effect CreateEffect(string code, params string[] args)
         {
-            if (args != null && args.Length == 0)
-            {
-                args = null;
-            }
-
+            Utils.CheckArgs(ref args);
             var ptr = NativeMethods.cgCreateEffect(this.Handle, code, args);
             return ptr == IntPtr.Zero ? null : new Effect(ptr, true);
         }
 
         public Effect CreateEffectFromFile(string filename, params string[] args)
         {
-            if (args != null && args.Length == 0)
-            {
-                args = null;
-            }
-
+            Utils.CheckArgs(ref args);
             var ptr = NativeMethods.cgCreateEffectFromFile(this.Handle, filename, args);
             return ptr == IntPtr.Zero ? null : new Effect(ptr, true);
         }
 
         public Obj CreateObj(ProgramType programType, string source, ProfileType profile, params string[] args)
         {
-            if (args != null && args.Length == 0)
-            {
-                args = null;
-            }
-
+            Utils.CheckArgs(ref args);
             var ptr = NativeMethods.cgCreateObj(this.Handle, programType, source, profile, args);
             return ptr == IntPtr.Zero ? null : new Obj(ptr, true);
         }
 
         public Obj CreateObjFromFile(ProgramType programType, string sourceFile, ProfileType profile, params string[] args)
         {
-            if (args != null && args.Length == 0)
-            {
-                args = null;
-            }
-
+            Utils.CheckArgs(ref args);
             var ptr = NativeMethods.cgCreateObjFromFile(this.Handle, programType, sourceFile, profile, args);
             return ptr == IntPtr.Zero ? null : new Obj(ptr, true);
         }
 
         public Program CreateProgram(ProgramType type, string source, ProfileType profile, string entry, params string[] args)
         {
-            if (args != null && args.Length == 0)
-            {
-                args = null;
-            }
-
+            Utils.CheckArgs(ref args);
             var ptr = NativeMethods.cgCreateProgram(this.Handle, type, source, profile, entry, args);
             return ptr == IntPtr.Zero ? null : new Program(ptr, true)
             {
 
         public Program CreateProgramFromFile(ProgramType type, string file, ProfileType profile, string entry, params string[] args)
         {
-            if (args != null && args.Length == 0)
-            {
-                args = null;
-            }
-
+            Utils.CheckArgs(ref args);
             var ptr = NativeMethods.cgCreateProgramFromFile(this.Handle, type, file, profile, entry, args);
             return ptr == IntPtr.Zero ? null : new Program(ptr, true)
             {
 
         public Program CreateProgram(ProfileType profile, string entry, params string[] args)
         {
-            if (args != null && args.Length == 0)
-            {
-                args = null;
-            }
-
+            Utils.CheckArgs(ref args);
             var ptr = NativeMethods.cgCreateProgramFromEffect(this.Handle, profile, entry, args);
             return ptr == IntPtr.Zero ? null : new Program(ptr, true);
         }
 {
     using System;
     using System.Collections.Generic;
+    using System.Linq;
     using System.Text;
 
     public static class Utils
 
         #region Public Static Methods
 
+        public static void CheckArgs(ref string[] args)
+        {
+            if (args == null)
+            {
+                return;
+            }
+            
+            if (args.Length == 0)
+            {
+                args = null;
+            }
+
+            if (args[args.Length - 1] != null)
+            {
+                args = args.Concat(new string[] { null }).ToArray();
+            }
+        }
+
         public static bool[] IntPtrToBoolArray(IntPtr values, int count)
         {
             if (count > 0)

ExampleBrowser/Examples/OpenTK/Advanced/IncludeString.cs

     {
         #region Fields
 
-        private static readonly string[] Args = { "-I", "shader", null };
+        private static readonly string[] Args = { "-I", "shader" };
 
         private ProfileType vertexProfile;
         private Program vertexProgram;
                "#include \"vertexProgram.cg\"\n",
                 vertexProfile,         /* Profile: OpenGL ARB vertex program */
                 "vertexProgram",           /* Entry function name */
-                Args);                    /* Include path options */
+                null);                    /* Include path options */
             vertexProgram.Load();
         }