Merge pull request #141 from Frassle/marshal

Fixes bugs in String marshalling.
This commit is contained in:
thefiddler 2014-06-20 08:45:03 +02:00
commit 4acbc2268d

View file

@ -202,10 +202,25 @@ namespace OpenTK
throw new OutOfMemoryException(); throw new OutOfMemoryException();
} }
for (int i = 0; i < str_array.Length; i++) int i = 0;
try
{ {
IntPtr str = MarshalStringToPtr(str_array[i]); for (i = 0; i < str_array.Length; i++)
Marshal.WriteIntPtr(ptr, i * IntPtr.Size, str); {
IntPtr str = MarshalStringToPtr(str_array[i]);
Marshal.WriteIntPtr(ptr, i * IntPtr.Size, str);
}
}
catch (OutOfMemoryException oom)
{
for (i = i - 1; i >= 0; --i)
{
Marshal.FreeHGlobal(Marshal.ReadIntPtr(ptr, i * IntPtr.Size));
}
Marshal.FreeHGlobal(ptr);
throw oom;
} }
} }
return ptr; return ptr;
@ -220,7 +235,7 @@ namespace OpenTK
{ {
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
Marshal.FreeHGlobal(Marshal.ReadIntPtr(ptr, length * IntPtr.Size)); Marshal.FreeHGlobal(Marshal.ReadIntPtr(ptr, i * IntPtr.Size));
} }
Marshal.FreeHGlobal(ptr); Marshal.FreeHGlobal(ptr);
} }