From 0a7e03cedc53388f8a20112666b57fd5ef6dae8a Mon Sep 17 00:00:00 2001 From: Quant1um Date: Mon, 21 Jul 2025 20:31:22 +0400 Subject: [PATCH] fix gl context memory leak on linux --- src/gl/x11.rs | 6 +++++- src/x11/window.rs | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/gl/x11.rs b/src/gl/x11.rs index b7aaca47..4a4de735 100644 --- a/src/gl/x11.rs +++ b/src/gl/x11.rs @@ -241,5 +241,9 @@ impl GlContext { } impl Drop for GlContext { - fn drop(&mut self) {} + fn drop(&mut self) { + unsafe { + glx::glXDestroyContext(self.display, self.context); + } + } } diff --git a/src/x11/window.rs b/src/x11/window.rs index 5b801eca..ca4db3cd 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -94,6 +94,10 @@ impl Drop for ParentHandle { } pub(crate) struct WindowInner { + // GlContext should be dropped **before** XcbConnection is dropped + #[cfg(feature = "opengl")] + gl_context: Option, + pub(crate) xcb_connection: XcbConnection, window_id: XWindow, pub(crate) window_info: WindowInfo, @@ -101,9 +105,6 @@ pub(crate) struct WindowInner { mouse_cursor: Cell, pub(crate) close_requested: Cell, - - #[cfg(feature = "opengl")] - gl_context: Option, } pub struct Window<'a> {