diff --git a/Source/OpenTK/Graphics/GraphicsContext.cs b/Source/OpenTK/Graphics/GraphicsContext.cs
index 55716374..61a7f58f 100644
--- a/Source/OpenTK/Graphics/GraphicsContext.cs
+++ b/Source/OpenTK/Graphics/GraphicsContext.cs
@@ -301,13 +301,23 @@ namespace OpenTK.Graphics
}
///
- /// Gets a System.Boolean indicating whether this Context is current in the calling thread.
+ /// Gets a indicating whether this instance is current in the calling thread.
///
public bool IsCurrent
{
get { return implementation.IsCurrent; }
}
+ ///
+ /// Gets a indicating whether this instance has been disposed.
+ /// It is an error to access any instance methods if this property returns true.
+ ///
+ public bool IsDisposed
+ {
+ get { return disposed && implementation.IsDisposed; }
+ private set { disposed = value; }
+ }
+
///
/// Gets or sets a value indicating whether VSync is enabled.
///
@@ -397,7 +407,7 @@ namespace OpenTK.Graphics
void Dispose(bool manual)
{
- if (!disposed)
+ if (!IsDisposed)
{
Debug.Print("Disposing context {0}.", (this as IGraphicsContextInternal).Context.ToString());
lock (context_lock)
@@ -410,7 +420,7 @@ namespace OpenTK.Graphics
if (implementation != null)
implementation.Dispose();
}
- disposed = true;
+ IsDisposed = true;
}
}
diff --git a/Source/OpenTK/Graphics/GraphicsContextBase.cs b/Source/OpenTK/Graphics/GraphicsContextBase.cs
index 8519f57a..4b15659c 100644
--- a/Source/OpenTK/Graphics/GraphicsContextBase.cs
+++ b/Source/OpenTK/Graphics/GraphicsContextBase.cs
@@ -37,6 +37,8 @@ namespace OpenTK.Graphics
{
#region Fields
+ bool disposed;
+
protected ContextHandle Handle;
protected GraphicsMode Mode;
@@ -50,6 +52,12 @@ namespace OpenTK.Graphics
public abstract bool IsCurrent { get; }
+ public bool IsDisposed
+ {
+ get { return disposed; }
+ protected set { disposed = value; }
+ }
+
public abstract bool VSync { get; set; }
public virtual void Update(IWindowInfo window) { }
diff --git a/Source/OpenTK/Graphics/IGraphicsContext.cs b/Source/OpenTK/Graphics/IGraphicsContext.cs
index 629c5c57..66e9e63f 100644
--- a/Source/OpenTK/Graphics/IGraphicsContext.cs
+++ b/Source/OpenTK/Graphics/IGraphicsContext.cs
@@ -31,10 +31,16 @@ namespace OpenTK.Graphics
void MakeCurrent(IWindowInfo window);
///
- /// Gets or sets a System.Boolean indicating whether the GraphicsContext is current in the calling thread.
+ /// Gets a indicating whether this instance is current in the calling thread.
///
bool IsCurrent { get; }
+ ///
+ /// Gets a indicating whether this instance has been disposed.
+ /// It is an error to access any instance methods if this property returns true.
+ ///
+ bool IsDisposed { get; }
+
///
/// Gets or sets a value indicating whether VSyncing is enabled.
///
diff --git a/Source/OpenTK/Platform/Dummy/DummyGLContext.cs b/Source/OpenTK/Platform/Dummy/DummyGLContext.cs
index 4f37962a..680d5cdb 100644
--- a/Source/OpenTK/Platform/Dummy/DummyGLContext.cs
+++ b/Source/OpenTK/Platform/Dummy/DummyGLContext.cs
@@ -89,7 +89,7 @@ namespace OpenTK.Platform.Dummy
#region --- IDisposable Members ---
- public override void Dispose() { }
+ public override void Dispose() { IsDisposed = true; }
#endregion
}
diff --git a/Source/OpenTK/Platform/Egl/EglContext.cs b/Source/OpenTK/Platform/Egl/EglContext.cs
index 10bb02de..4abaf8a1 100644
--- a/Source/OpenTK/Platform/Egl/EglContext.cs
+++ b/Source/OpenTK/Platform/Egl/EglContext.cs
@@ -40,7 +40,6 @@ namespace OpenTK.Platform.Egl
EglWindowInfo WindowInfo;
EGLContext HandleAsEGLContext { get { return new EGLContext(Handle.Handle); } set { Handle = new ContextHandle(value.Handle.Value); } }
bool vsync = true; // Default vsync value is defined as 1 (true) in EGL.
- bool disposed = false;
#endregion
@@ -141,7 +140,7 @@ namespace OpenTK.Platform.Egl
// thread?
void Dispose(bool manual)
{
- if (!disposed)
+ if (!IsDisposed)
{
if (manual)
{
@@ -152,7 +151,7 @@ namespace OpenTK.Platform.Egl
{
Debug.Print("[Warning] {0}:{1} was not disposed.", this.GetType().Name, HandleAsEGLContext.Handle);
}
- disposed = true;
+ IsDisposed = true;
}
}
diff --git a/Source/OpenTK/Platform/MacOS/AglContext.cs b/Source/OpenTK/Platform/MacOS/AglContext.cs
index 86e901ed..55dd8d0f 100644
--- a/Source/OpenTK/Platform/MacOS/AglContext.cs
+++ b/Source/OpenTK/Platform/MacOS/AglContext.cs
@@ -335,8 +335,7 @@ namespace OpenTK.Platform.MacOS
void Dispose(bool disposing)
{
-
- if (Handle.Handle == IntPtr.Zero)
+ if (IsDisposed || Handle.Handle == IntPtr.Zero)
return;
Debug.Print("Disposing of AGL context.");
@@ -370,6 +369,8 @@ namespace OpenTK.Platform.MacOS
{
throw new MacOSException((OSStatus)Agl.GetError(), Agl.ErrorString(Agl.GetError()));
}
+
+ IsDisposed = true;
}
#endregion
diff --git a/Source/OpenTK/Platform/Windows/WinGLContext.cs b/Source/OpenTK/Platform/Windows/WinGLContext.cs
index fcec4c72..fdf1024f 100644
--- a/Source/OpenTK/Platform/Windows/WinGLContext.cs
+++ b/Source/OpenTK/Platform/Windows/WinGLContext.cs
@@ -32,8 +32,6 @@ namespace OpenTK.Platform.Windows
bool vsync_supported;
- bool disposed;
-
#region --- Contructors ---
static WinGLContext()
@@ -305,7 +303,7 @@ namespace OpenTK.Platform.Windows
private void Dispose(bool calledManually)
{
- if (!disposed)
+ if (!IsDisposed)
{
if (calledManually)
{
@@ -316,7 +314,7 @@ namespace OpenTK.Platform.Windows
Debug.Print("[Warning] OpenGL context {0} leaked. Did you forget to call IGraphicsContext.Dispose()?",
Handle.Handle);
}
- disposed = true;
+ IsDisposed = true;
}
}
diff --git a/Source/OpenTK/Platform/X11/X11GLContext.cs b/Source/OpenTK/Platform/X11/X11GLContext.cs
index 4b7f8e40..714b6de4 100644
--- a/Source/OpenTK/Platform/X11/X11GLContext.cs
+++ b/Source/OpenTK/Platform/X11/X11GLContext.cs
@@ -26,8 +26,6 @@ namespace OpenTK.Platform.X11
bool glx_loaded;
GraphicsMode graphics_mode;
- bool disposed;
-
#region --- Constructors ---
public X11GLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shared, bool direct,
@@ -298,7 +296,7 @@ namespace OpenTK.Platform.X11
private void Dispose(bool manuallyCalled)
{
- if (!disposed)
+ if (!IsDisposed)
{
if (manuallyCalled)
{
@@ -312,7 +310,7 @@ namespace OpenTK.Platform.X11
{
Debug.Print("[Warning] {0} leaked.", this.GetType().Name);
}
- disposed = true;
+ IsDisposed = true;
}
}