From 103b8a83c3e2e86bf141e1877fcb8ed4f4e2a422 Mon Sep 17 00:00:00 2001 From: Sam Carlberg Date: Wed, 12 Oct 2016 16:51:53 -0400 Subject: [PATCH] Fix webcam sources failing to stop when opening saved projects (#686) --- .../main/java/edu/wpi/grip/core/sources/CameraSource.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/edu/wpi/grip/core/sources/CameraSource.java b/core/src/main/java/edu/wpi/grip/core/sources/CameraSource.java index 0545e5fc29..0fbb07e5d5 100644 --- a/core/src/main/java/edu/wpi/grip/core/sources/CameraSource.java +++ b/core/src/main/java/edu/wpi/grip/core/sources/CameraSource.java @@ -333,7 +333,12 @@ public void onSourceRemovedEvent(SourceRemovedEvent event) throws InterruptedExc TimeoutException, IOException { if (event.getSource() == this) { try { - this.stopAsync(); + // Stop the camera service and wait for it to terminate. + // If we just use stopAsync(), the camera service won't always have terminated by the time + // a new camera source is added. For webcam sources, this means that the video stream + // won't be freed and new sources won't be able to connect to the webcam until the + // application is closed. + this.stopAndAwait(); } finally { this.eventBus.unregister(this); }