protected override void Dispose(bool calledManually) { if (ContextHandle == IntPtr.Zero) { return; } if (calledManually) { // This will fail if the user calls Dispose() on thread X when the context is current on thread Y. Wgl.wglDeleteContext(ContextHandle); } else { Debug.Print("=== [Warning] OpenGL context leaked ==="); } ContextHandle = IntPtr.Zero; }
private void DestroyContext() { if (ContextHandle == IntPtr.Zero) { return; } try { // This will fail if the user calls Dispose() on thread X when the context is current on thread Y. if (!Wgl.wglDeleteContext(ContextHandle)) { Debug.Print("Failed to destroy OpenGL context {0}. Error: {1}", ContextHandle.ToString(), Marshal.GetLastWin32Error()); } } catch (AccessViolationException e) { Debug.Print("An access violation occured while destroying the OpenGL context. Please report at http://www.opentk.com."); Debug.Print("Marshal.GetLastWin32Error(): {0}", Marshal.GetLastWin32Error().ToString()); Debug.Print(e.ToString()); } ContextHandle = IntPtr.Zero; }