refactor: egl cxt teardown

This commit is contained in:
drendog 2025-10-25 23:22:24 +02:00
parent 6621db62c8
commit 87fc46750c
Signed by: dwenya
GPG key ID: 8DD77074645332D0

View file

@ -26,8 +26,8 @@ use std::{
use wayland_client::backend::ObjectId; use wayland_client::backend::ObjectId;
pub struct EGLContext { pub struct EGLContext {
context: PossiblyCurrentContext,
surface: Surface<WindowSurface>, surface: Surface<WindowSurface>,
context: PossiblyCurrentContext,
} }
#[derive(Default)] #[derive(Default)]
@ -105,7 +105,7 @@ impl EGLContextBuilder {
.make_current(&surface) .make_current(&surface)
.map_err(|e| LayerShikaError::EGLContextCreation(format!("Unable to activate EGL context: {e}. This may indicate a problem with the graphics drivers.")))?; .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<RawDisplayHandle> { fn create_wayland_display_handle(display_id: &ObjectId) -> Result<RawDisplayHandle> {
let display = NonNull::new(display_id.as_ptr().cast::<c_void>()).ok_or_else(|| { let display = NonNull::new(display_id.as_ptr().cast::<c_void>()).ok_or_else(|| {
LayerShikaError::InvalidInput("Failed to create NonNull pointer for display".into()) LayerShikaError::InvalidInput("Failed to create NonNull pointer for display".into())