diff --git a/src/native.rs b/src/native.rs index dd118f5..d24af14 100644 --- a/src/native.rs +++ b/src/native.rs @@ -3268,6 +3268,25 @@ impl HasContext for Context { } } +impl Drop for Context { + fn drop(&mut self) { + if let Some(_) = self.debug_callback.take() { + } else { + return; + } + + // Unset the debug callback before destroying the context. + unsafe { + let gl = &self.raw; + if gl.DebugMessageCallback_is_loaded() { + gl.DebugMessageCallback(None, std::ptr::null()); + } else { + gl.DebugMessageCallbackKHR(None, std::ptr::null()); + } + } + } +} + extern "system" fn raw_debug_message_callback( source: u32, gltype: u32,