From 72dba49535c8adfcb49aa15f25df57ef08125c96 Mon Sep 17 00:00:00 2001 From: Dario Lencina Date: Fri, 27 Dec 2024 11:21:21 -0500 Subject: [PATCH] add better logging for bad buffer size --- examples/threaded-capture/src/main.rs | 2 +- nokhwa-core/src/types.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/threaded-capture/src/main.rs b/examples/threaded-capture/src/main.rs index 6c216dc..3280d18 100644 --- a/examples/threaded-capture/src/main.rs +++ b/examples/threaded-capture/src/main.rs @@ -32,7 +32,7 @@ fn main() { let format = RequestedFormat::new::(RequestedFormatType::AbsoluteHighestFrameRate); - let first_camera = cameras.first().unwrap(); + let first_camera = cameras.get(1).unwrap(); let mut threaded = CallbackCamera::new(first_camera.index().clone(), format, |buffer| { let image = buffer.decode_image::().unwrap(); diff --git a/nokhwa-core/src/types.rs b/nokhwa-core/src/types.rs index 101cd07..9b4ea9a 100644 --- a/nokhwa-core/src/types.rs +++ b/nokhwa-core/src/types.rs @@ -1759,11 +1759,13 @@ pub fn buf_nv12_to_rgb( }); } - if data.len() != ((resolution.width() * resolution.height() * 3) / 2) as usize { + let expected_len = ((resolution.width() * resolution.height() * 3) / 2) as usize; + + if data.len() != expected_len { return Err(NokhwaError::ProcessFrameError { src: FrameFormat::NV12, destination: "RGB".to_string(), - error: "bad input buffer size".to_string(), + error: format!("bad input buffer size, expected {} but got {}", expected_len, data.len()), }); }