Open qzd1989 opened 3 months ago
here is my system info
Hey there @qzd1989, can you share a minimal code example to reproduce this issue? I can't tell much about what's going on with just a stack trace (This does lead me to believe there's some work we can do to handle stream errors more reliably though).
Hey there @qzd1989, can you share a minimal code example to reproduce this issue? I can't tell much about what's going on with just a stack trace (This does lead me to believe there's some work we can do to handle stream errors more reliably though).
Thank you! Yes, I reproduced the BUG 100% by using code below. Before you run this code, you should open the app "calculator" or "chrome" first on mac. :) "calculator" or "chrome" window is showed on the middle display.
rustc 1.82.0-nightly (13a52890d 2024-08-14)
[dependencies]
crabgrab = { version = "0.4.0", features = ["bitmap"] }
tokio = { version = "1.39.3", features = ["full", "macros", "rt-multi-thread"] }
use crabgrab::{feature::bitmap::VideoFrameBitmap as _, prelude::*};
fn main() {
//100% panic when I close them manually
// let identifier = "com.apple.calculator".to_string();
let identifier = "com.google.chrome".to_string();
let runtime = tokio::runtime::Runtime::new().unwrap();
runtime.block_on(async move {
let token = match CaptureStream::test_access(false) {
Some(token) => token,
None => CaptureStream::request_access(false)
.await
.expect("Expected capture access"),
};
let config = get_capture_config_by_identifier(identifier.clone()).await;
if let None = config {
return;
}
let callback = move |stream_event| match stream_event {
Ok(event) => {
if let StreamEvent::Video(frame) = event {
match frame.get_bitmap() {
Ok(bitmap) => match bitmap {
FrameBitmap::BgraUnorm8x4(data) => {
//Another BUG: data.width/height won't change while I change the window size.
//see here: https://github.com/AugmendTech/CrabGrab/issues/44
println!("window size: ({:?}, {:?})", data.width, data.height);
}
_ => {}
},
Err(_) => {}
}
}
}
Err(_) => {}
};
let mut stream = CaptureStream::new(token, config.unwrap(), callback).unwrap();
tokio::task::block_in_place(|| std::thread::sleep(std::time::Duration::from_millis(40000)));
stream.stop().unwrap();
});
}
async fn get_window_by_identifier(identifier: String) -> Option<CapturableWindow> {
let mut monitor: Option<CapturableWindow> = None;
let filter = CapturableContentFilter::NORMAL_WINDOWS;
let content = CapturableContent::new(filter).await.unwrap();
for window in content.windows() {
if window.application().identifier().to_lowercase() == identifier {
monitor = Some(window);
}
}
return monitor;
}
async fn get_capture_config_by_identifier(identifier: String) -> Option<CaptureConfig> {
match get_window_by_identifier(identifier.clone()).await {
Some(window) => {
Some(CaptureConfig::with_window(window, CapturePixelFormat::Bgra8888).unwrap())
}
None => None,
}
}
https://github.com/user-attachments/assets/0b3ff2ab-fd06-49a0-806e-a8503f969d1c
when I capture window: com.apple.calculator the program will 100% crush when I close the calculator window. the panic line is : crabgrab::platform::macos::objc_wrap::sc_stream_handler_did_stop_with_error panic log is: