public void Dispose() { if (Context != ContextHandle.Zero) { Wgl.MakeCurrent(IntPtr.Zero, IntPtr.Zero); Wgl.DeleteContext(Context.Handle); } }
private void DestroyContext() { if (Handle != ContextHandle.Zero) { try { // This will fail if the user calls Dispose() on thread X when the context is current on thread Y. if (!Wgl.DeleteContext(Handle.Handle)) { Debug.Print("Failed to destroy OpenGL context {0}. Error: {1}", Handle.ToString(), Marshal.GetLastWin32Error()); } } catch (AccessViolationException e) { Debug.WriteLine("An access violation occured while destroying the OpenGL context. Please report at https://github.com/opentk/opentk/issues"); Debug.Indent(); Debug.Print("Marshal.GetLastWin32Error(): {0}", Marshal.GetLastWin32Error().ToString()); Debug.WriteLine(e.ToString()); Debug.Unindent(); } Handle = ContextHandle.Zero; } }