Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix on_closed not called when using start_free_threaded #47

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ pub trait GraphicsCaptureApiHandler: Sized {
Self::new(settings.flags).map_err(GraphicsCaptureApiError::NewHandlerError)?,
));

let item = match settings.item.try_into() {
Ok(item) => item,
Err(_) => return Err(GraphicsCaptureApiError::ItemConvertFailed),
};
let item = settings
.item
.try_into()
.map_err(|_| GraphicsCaptureApiError::ItemConvertFailed)?;

let mut capture = GraphicsCaptureApi::new(
item,
Expand Down Expand Up @@ -332,7 +332,7 @@ pub trait GraphicsCaptureApiHandler: Sized {
/// # Returns
///
/// Returns `Ok(CaptureControl)` if the capture was successful, otherwise returns an error of type `GraphicsCaptureApiError`.
fn start_free_threaded<T: TryInto<GraphicsCaptureItem> + Send>(
fn start_free_threaded<T: TryInto<GraphicsCaptureItem> + Send + 'static>(
settings: Settings<Self::Flags, T>,
) -> Result<CaptureControl<Self, Self::Error>, GraphicsCaptureApiError<Self::Error>>
where
Expand All @@ -342,11 +342,6 @@ pub trait GraphicsCaptureApiHandler: Sized {
let (halt_sender, halt_receiver) = mpsc::channel::<Arc<AtomicBool>>();
let (callback_sender, callback_receiver) = mpsc::channel::<Arc<Mutex<Self>>>();

let item = match settings.item.try_into() {
Ok(item) => item,
Err(_) => return Err(GraphicsCaptureApiError::ItemConvertFailed),
};

let thread_handle = thread::spawn(
move || -> Result<(), GraphicsCaptureApiError<Self::Error>> {
// Initialize WinRT
Expand Down Expand Up @@ -376,6 +371,11 @@ pub trait GraphicsCaptureApiHandler: Sized {
Self::new(settings.flags).map_err(GraphicsCaptureApiError::NewHandlerError)?,
));

let item = settings
.item
.try_into()
.map_err(|_| GraphicsCaptureApiError::ItemConvertFailed)?;

let mut capture = GraphicsCaptureApi::new(
item,
callback.clone(),
Expand Down
Loading