Skip to content

Commit

Permalink
add better logging for bad buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
darioalessandro committed Dec 27, 2024
1 parent 074f3da commit 72dba49
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/threaded-capture/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() {

let format = RequestedFormat::new::<RgbFormat>(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::<RgbAFormat>().unwrap();
Expand Down
6 changes: 4 additions & 2 deletions nokhwa-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
});
}

Expand Down

0 comments on commit 72dba49

Please sign in to comment.