This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
bug: panic when close the window which is capturing. #45
Comments
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.
[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,
}
} 2024-08-22.15.47.42.mp4 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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:
The text was updated successfully, but these errors were encountered: