Skip to content

Commit

Permalink
Merge pull request #47 from SegaraRai/fix-closed-event-not-received
Browse files Browse the repository at this point in the history
Fix `on_closed` not called when using `start_free_threaded`
  • Loading branch information
NiiightmareXD authored May 7, 2024
2 parents 08c9b59 + 88a5b60 commit 409fa1c
Showing 1 changed file with 10 additions and 10 deletions.
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

0 comments on commit 409fa1c

Please sign in to comment.