Added stack traces to automatic error checking.

Added GraphicsContext.ErrorChecking property to temporarily disable error checking if necessary.
Error checking is now added to all functions in debug mode (the generator would miss specific CLS-compliant overloads before).
This commit is contained in:
the_fiddler 2009-03-29 21:41:30 +00:00
parent 0888af5abf
commit 3f41f1eaf5
10 changed files with 2171 additions and 21 deletions

View file

@ -368,22 +368,13 @@ namespace Bind.Structures
foreach (Function f in wrappers)
{
Bind.Structures.Function.Wrappers.AddChecked(f);
//Bind.Structures.Function.Wrappers.Add(f);
if (!f.CLSCompliant)
{
Function cls = new Function(f);
cls.Body.Clear();
if (!cls.NeedsWrapper)
{
cls.Body.Add((f.ReturnType.CurrentType != "void" ? "return " + this.CallString() : this.CallString()) + ";");
}
else
{
cls.CreateBody(true);
//cls.Body.AddRange(this.CreateBody(cls, true));
}
cls.CreateBody(true);
bool somethingChanged = false;
for (int i = 0; i < f.Parameters.Count; i++)

View file

@ -401,6 +401,10 @@ namespace Bind.Structures
public void CreateBody(bool wantCLSCompliance)
{
if (this.Name.Contains("NewList"))
{
}
Function f = new Function(this);
f.Body.Clear();

File diff suppressed because it is too large Load diff

View file

@ -107,7 +107,7 @@ namespace OpenTK.Graphics
#endregion
#region --- Public Methods ---
#region --- Public Members ---
#region public static bool SupportsExtension(string name)

View file

@ -28,7 +28,8 @@ namespace OpenTK.Graphics
// Indicates that this context was created through external means, e.g. Tao.Sdl or GLWidget#.
// In this case, We'll assume that the external program will manage the lifetime of this
// context - we'll not destroy it manually.
bool is_external;
//bool is_external;
bool check_errors = true;
static bool share_contexts = true;
static bool direct_rendering = true;
@ -132,7 +133,6 @@ namespace OpenTK.Graphics
public static GraphicsContext CreateDummyContext()
{
GraphicsContext context = new GraphicsContext();
context.is_external = true;
context.implementation = new OpenTK.Platform.Dummy.DummyGLContext(GraphicsMode.Default);
lock (context_lock)
@ -245,7 +245,7 @@ namespace OpenTK.Graphics
[Conditional("DEBUG")]
internal void ResetErrors()
{
if (!inside_begin_region)
if (check_errors && !inside_begin_region)
{
while (GL.GetError() != ErrorCode.NoError)
{ }
@ -256,7 +256,7 @@ namespace OpenTK.Graphics
[Conditional("DEBUG")]
internal void CheckErrors()
{
if (!inside_begin_region)
if (check_errors && !inside_begin_region)
{
error_list.Clear();
ErrorCode error;
@ -271,13 +271,20 @@ namespace OpenTK.Graphics
StringBuilder sb = new StringBuilder();
foreach (ErrorCode e in error_list)
{
sb.Append(e.ToString());
sb.Append(", ");
if (e != ErrorCode.NoError)
{
sb.Append(e.ToString());
sb.Append(", ");
}
else
break;
}
sb.Remove(sb.Length - 2, 2);
sb.Remove(sb.Length - 2, 2); // Remove the last comma
Debug.Assert(error_list.Count == 1, "OpenTK detected an OpenGL error.",
String.Format("The following errors where reported: \"{0}\"", sb.ToString()));
Debug.Print(String.Format("OpenGL error(s) detected: {0}", sb.ToString()));
Debug.Indent();
Debug.WriteLine(new StackTrace(true).ToString());
Debug.Unindent();
}
}
}
@ -305,6 +312,17 @@ namespace OpenTK.Graphics
#region --- IGraphicsContext Members ---
/// <summary>
/// Gets or sets a System.Boolean, indicating whether automatic error checking should be performed.
/// Influences the debug version of OpenTK.dll, only.
/// </summary>
/// <remarks>Automatic error checking will clear the OpenGL error state. Set CheckErrors to false if you use
/// the OpenGL error state in your code flow (e.g. for checking supported texture formats).</remarks>
public bool ErrorChecking
{
get { return check_errors; }
set { check_errors = value; }
}
/// <summary>
/// Creates an OpenGL context with the specified direct/indirect rendering mode and sharing state with the
/// specified IGraphicsContext.
@ -485,7 +503,7 @@ namespace OpenTK.Graphics
available_contexts.Remove((this as IGraphicsContextInternal).Context);
}
if (manual && !is_external)
if (manual)
{
if (implementation != null)
implementation.Dispose();

View file

@ -54,6 +54,12 @@ namespace OpenTK.Graphics
/// <summary>Gets the GraphicsMode of this instance.</summary>
GraphicsMode GraphicsMode { get; }
/// <summary>
/// Gets or sets a System.Boolean, indicating whether automatic error checking should be performed.
/// Influences the debug version of OpenTK.dll, only.
/// </summary>
bool ErrorChecking { get; set; }
}
public delegate void DestroyEvent<T>(T sender, EventArgs e);

View file

@ -71,6 +71,12 @@ namespace OpenTK.Platform.Dummy
{
}
public bool ErrorChecking
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
#endregion
#region --- IDisposable Members ---

View file

@ -338,6 +338,12 @@ namespace OpenTK.Platform.MacOS
get { return graphics_mode; }
}
public bool ErrorChecking
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
#endregion
#region IDisposable Members

View file

@ -230,6 +230,12 @@ namespace OpenTK.Platform.Windows
#endregion
public bool ErrorChecking
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public event DestroyEvent<IGraphicsContext> Destroy;
#endregion

View file

@ -301,6 +301,12 @@ namespace OpenTK.Platform.X11
throw new NotSupportedException("Use OpenTK.GraphicsContext instead.");
}
public bool ErrorChecking
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
#endregion
#region --- IGLContextInternal Members ---