From 87fc46750c224af1ac9ecf356fe0d307e15fb2fe Mon Sep 17 00:00:00 2001 From: drendog Date: Sat, 25 Oct 2025 23:22:24 +0200 Subject: [PATCH] refactor: egl cxt teardown --- src/rendering/egl_context.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/rendering/egl_context.rs b/src/rendering/egl_context.rs index 4334446..d0d755a 100644 --- a/src/rendering/egl_context.rs +++ b/src/rendering/egl_context.rs @@ -26,8 +26,8 @@ use std::{ use wayland_client::backend::ObjectId; pub struct EGLContext { - context: PossiblyCurrentContext, surface: Surface, + context: PossiblyCurrentContext, } #[derive(Default)] @@ -105,7 +105,7 @@ impl EGLContextBuilder { .make_current(&surface) .map_err(|e| LayerShikaError::EGLContextCreation(format!("Unable to activate EGL context: {e}. This may indicate a problem with the graphics drivers.")))?; - Ok(EGLContext { context, surface }) + Ok(EGLContext { surface, context }) } } @@ -124,6 +124,18 @@ impl EGLContext { } } +impl Drop for EGLContext { + fn drop(&mut self) { + if self.context.is_current() { + if let Err(e) = self.context.make_not_current_in_place() { + log::error!("Failed to make EGL context not current during cleanup: {e}"); + } else { + log::debug!("Successfully made EGL context not current during cleanup"); + } + } + } +} + fn create_wayland_display_handle(display_id: &ObjectId) -> Result { let display = NonNull::new(display_id.as_ptr().cast::()).ok_or_else(|| { LayerShikaError::InvalidInput("Failed to create NonNull pointer for display".into())