Skip to content

Commit f7326ce

Browse files
authored
fix gl context memory leak on linux (#215)
1 parent 101c864 commit f7326ce

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/gl/x11.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,9 @@ impl GlContext {
241241
}
242242

243243
impl Drop for GlContext {
244-
fn drop(&mut self) {}
244+
fn drop(&mut self) {
245+
unsafe {
246+
glx::glXDestroyContext(self.display, self.context);
247+
}
248+
}
245249
}

src/x11/window.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,17 @@ impl Drop for ParentHandle {
9494
}
9595

9696
pub(crate) struct WindowInner {
97+
// GlContext should be dropped **before** XcbConnection is dropped
98+
#[cfg(feature = "opengl")]
99+
gl_context: Option<GlContext>,
100+
97101
pub(crate) xcb_connection: XcbConnection,
98102
window_id: XWindow,
99103
pub(crate) window_info: WindowInfo,
100104
visual_id: Visualid,
101105
mouse_cursor: Cell<MouseCursor>,
102106

103107
pub(crate) close_requested: Cell<bool>,
104-
105-
#[cfg(feature = "opengl")]
106-
gl_context: Option<GlContext>,
107108
}
108109

109110
pub struct Window<'a> {

0 commit comments

Comments
 (0)