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

View file

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

File diff suppressed because it is too large Load diff

View file

@ -107,7 +107,7 @@ namespace OpenTK.Graphics
#endregion #endregion
#region --- Public Methods --- #region --- Public Members ---
#region public static bool SupportsExtension(string name) #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#. // 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 // In this case, We'll assume that the external program will manage the lifetime of this
// context - we'll not destroy it manually. // context - we'll not destroy it manually.
bool is_external; //bool is_external;
bool check_errors = true;
static bool share_contexts = true; static bool share_contexts = true;
static bool direct_rendering = true; static bool direct_rendering = true;
@ -132,7 +133,6 @@ namespace OpenTK.Graphics
public static GraphicsContext CreateDummyContext() public static GraphicsContext CreateDummyContext()
{ {
GraphicsContext context = new GraphicsContext(); GraphicsContext context = new GraphicsContext();
context.is_external = true;
context.implementation = new OpenTK.Platform.Dummy.DummyGLContext(GraphicsMode.Default); context.implementation = new OpenTK.Platform.Dummy.DummyGLContext(GraphicsMode.Default);
lock (context_lock) lock (context_lock)
@ -245,7 +245,7 @@ namespace OpenTK.Graphics
[Conditional("DEBUG")] [Conditional("DEBUG")]
internal void ResetErrors() internal void ResetErrors()
{ {
if (!inside_begin_region) if (check_errors && !inside_begin_region)
{ {
while (GL.GetError() != ErrorCode.NoError) while (GL.GetError() != ErrorCode.NoError)
{ } { }
@ -256,7 +256,7 @@ namespace OpenTK.Graphics
[Conditional("DEBUG")] [Conditional("DEBUG")]
internal void CheckErrors() internal void CheckErrors()
{ {
if (!inside_begin_region) if (check_errors && !inside_begin_region)
{ {
error_list.Clear(); error_list.Clear();
ErrorCode error; ErrorCode error;
@ -271,13 +271,20 @@ namespace OpenTK.Graphics
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
foreach (ErrorCode e in error_list) foreach (ErrorCode e in error_list)
{ {
sb.Append(e.ToString()); if (e != ErrorCode.NoError)
sb.Append(", "); {
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.", Debug.Print(String.Format("OpenGL error(s) detected: {0}", sb.ToString()));
String.Format("The following errors where reported: \"{0}\"", sb.ToString())); Debug.Indent();
Debug.WriteLine(new StackTrace(true).ToString());
Debug.Unindent();
} }
} }
} }
@ -305,6 +312,17 @@ namespace OpenTK.Graphics
#region --- IGraphicsContext Members --- #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> /// <summary>
/// Creates an OpenGL context with the specified direct/indirect rendering mode and sharing state with the /// Creates an OpenGL context with the specified direct/indirect rendering mode and sharing state with the
/// specified IGraphicsContext. /// specified IGraphicsContext.
@ -485,7 +503,7 @@ namespace OpenTK.Graphics
available_contexts.Remove((this as IGraphicsContextInternal).Context); available_contexts.Remove((this as IGraphicsContextInternal).Context);
} }
if (manual && !is_external) if (manual)
{ {
if (implementation != null) if (implementation != null)
implementation.Dispose(); implementation.Dispose();

View file

@ -54,6 +54,12 @@ namespace OpenTK.Graphics
/// <summary>Gets the GraphicsMode of this instance.</summary> /// <summary>Gets the GraphicsMode of this instance.</summary>
GraphicsMode GraphicsMode { get; } 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); 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 #endregion
#region --- IDisposable Members --- #region --- IDisposable Members ---

View file

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

View file

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

View file

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