Use StringBuilder.Capacity to specify the available buffer size in OpenGL interop (StringBuilder.Length is invalid in this case).

Added workaround for Mono 1.9.1 issue, where StringBuilder return truncated results when used in interop. Doubling the StringBuilder capacity fixes this issue.
This commit is contained in:
the_fiddler 2009-10-21 17:26:07 +00:00
parent ab0a0f31ff
commit 8fbea23db2

View file

@ -342,6 +342,9 @@ namespace OpenTK.Graphics.OpenGL
#pragma warning disable 1572
#pragma warning disable 1573
// Note: Mono 1.9.1 truncates StringBuilder results (for 'out string' parameters).
// We work around this issue by doubling the StringBuilder capacity.
#region public static void Color[34]() overloads
public static void Color3(System.Drawing.Color color)
@ -641,9 +644,9 @@ namespace OpenTK.Graphics.OpenGL
{
int length;
GetProgram(program, OpenTK.Graphics.OpenGL.ProgramParameter.ActiveAttributeMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length);
GetActiveAttrib(program, index, sb.Length, out length, out size, out type, sb);
GetActiveAttrib(program, index, sb.Capacity, out length, out size, out type, sb);
return sb.ToString();
}
@ -657,7 +660,7 @@ namespace OpenTK.Graphics.OpenGL
GetProgram(program, OpenTK.Graphics.OpenGL.ProgramParameter.ActiveUniformMaxLength, out length);
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length);
GetActiveUniform(program, uniformIndex, sb.Length, out length, out size, out type, sb);
GetActiveUniform(program, uniformIndex, sb.Capacity, out length, out size, out type, sb);
return sb.ToString();
}
@ -669,11 +672,9 @@ namespace OpenTK.Graphics.OpenGL
{
int length;
GetProgram(program, OpenTK.Graphics.OpenGL.ProgramParameter.ActiveUniformMaxLength, out length);
if (length == 0)
return String.Empty;
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2);
StringBuilder sb = new StringBuilder(length);
GetActiveUniformName(program, uniformIndex, sb.Length, out length, sb);
GetActiveUniformName(program, uniformIndex, sb.Capacity, out length, sb);
return sb.ToString();
}
@ -685,11 +686,9 @@ namespace OpenTK.Graphics.OpenGL
{
int length;
GetProgram(program, OpenTK.Graphics.OpenGL.ProgramParameter.ActiveUniformBlockMaxNameLength, out length);
if (length == 0)
return String.Empty;
StringBuilder sb = new StringBuilder(length == 0 ? 1 : length * 2);
StringBuilder sb = new StringBuilder(length);
GetActiveUniformBlockName(program, uniformIndex, sb.Length, out length, sb);
GetActiveUniformBlockName(program, uniformIndex, sb.Capacity, out length, sb);
return sb.ToString();
}
@ -732,7 +731,7 @@ namespace OpenTK.Graphics.OpenGL
info = String.Empty;
return;
}
StringBuilder sb = new StringBuilder(length);
StringBuilder sb = new StringBuilder(length * 2);
GL.GetShaderInfoLog((UInt32)shader, sb.Capacity, &length, sb);
info = sb.ToString();
}
@ -763,7 +762,7 @@ namespace OpenTK.Graphics.OpenGL
info = String.Empty;
return;
}
StringBuilder sb = new StringBuilder(length);
StringBuilder sb = new StringBuilder(length * 2);
GL.GetProgramInfoLog((UInt32)program, sb.Capacity, &length, sb);
info = sb.ToString();
}