Skip to content

Commit 55f5a17

Browse files
Fix problem with repeated start and stop grabbing in async code
The filedescriptor was not reset on stop grabbing, which caused a C++ exception on restarting the grabbing.
1 parent b345f3e commit 55f5a17

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,10 @@ impl<'a> InstantCamera<'a> {
563563
}
564564

565565
pub fn stop_grabbing(&self) -> PylonResult<()> {
566-
ffi::instant_camera_stop_grabbing(&self.inner).into_rust()
566+
ffi::instant_camera_stop_grabbing(&self.inner).into_rust()?;
567+
#[cfg(feature = "stream")]
568+
self.fd.replace(None);
569+
Ok(())
567570
}
568571

569572
pub fn is_grabbing(&self) -> bool {

src/stream.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,23 @@ mod tests {
9090

9191
Ok(())
9292
}
93+
94+
#[tokio::test]
95+
async fn start_stop_loop_works() -> PylonResult<()> {
96+
let pylon = Pylon::new();
97+
let cam = TlFactory::instance(&pylon).create_first_device()?;
98+
cam.open()?;
99+
tokio::pin!(cam);
100+
for _ in 0..5 {
101+
let mut images = 10;
102+
cam.start_grabbing(&GrabOptions::default().count(images))?;
103+
while let Some(res) = cam.next().await {
104+
images -= 1;
105+
assert!(res.grab_succeeded()?);
106+
}
107+
assert_eq!(images, 0);
108+
cam.stop_grabbing()?;
109+
}
110+
Ok(())
111+
}
93112
}

0 commit comments

Comments
 (0)