From 8e81a8f0f3bd0c33d5b368bf909e18caea60b2a1 Mon Sep 17 00:00:00 2001 From: Maxim Baz Date: Thu, 24 Oct 2024 00:19:50 +0200 Subject: [PATCH] Try destroying WlBuffer only on ready or failed events --- src/frame/capturer/wayland.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/frame/capturer/wayland.rs b/src/frame/capturer/wayland.rs index 144a0fb..40a522e 100644 --- a/src/frame/capturer/wayland.rs +++ b/src/frame/capturer/wayland.rs @@ -39,6 +39,7 @@ pub struct Capturer { output_global_id: Option, screencopy_manager: Option, dmabuf: Option, + wlbuffer: Option, dmabuf_manager: Option, pending_frame: Option, controller: Option, @@ -60,6 +61,7 @@ impl Capturer { output_global_id: None, screencopy_manager: None, dmabuf: None, + wlbuffer: None, dmabuf_manager: None, pending_frame: None, controller: None, @@ -420,8 +422,8 @@ impl Dispatch for Capturer { ); frame.copy(&buffer); - buffer.destroy(); + state.wlbuffer = Some(buffer); state.pending_frame = Some(pending_frame); } @@ -440,6 +442,9 @@ impl Dispatch for Capturer { frame.destroy(); state.pending_frame = None; + if let Some(buffer) = state.wlbuffer.take() { + buffer.destroy() + } thread::sleep(DELAY_SUCCESS); state.is_processing_frame = false; @@ -448,6 +453,9 @@ impl Dispatch for Capturer { zwlr_screencopy_frame_v1::Event::Failed {} => { frame.destroy(); state.pending_frame = None; + if let Some(buffer) = state.wlbuffer.take() { + buffer.destroy() + } log::error!("Frame copy failed"); thread::sleep(DELAY_FAILURE);