Skip to content

Commit bf0eb35

Browse files
committed
Fixes stopped camera exception stop pipeline event
This fixes an issue where the onStopPipeline event would throw an exception if the camera source was already stopped. Closes #353
1 parent 1b4e055 commit bf0eb35

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

core/src/main/java/edu/wpi/grip/core/sources/CameraSource.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,10 @@ private static Properties createProperties(int deviceNumber) {
334334
* @param event
335335
*/
336336
@Subscribe
337-
public synchronized void onStopPipeline(StopPipelineEvent event) throws InterruptedException, IOException, TimeoutException {
338-
this.stop();
337+
public void onStopPipeline(StopPipelineEvent event) throws InterruptedException, IOException, TimeoutException {
338+
if (this.isStarted()) {
339+
this.stop();
340+
}
339341
}
340342

341343
}

core/src/test/java/edu/wpi/grip/core/sources/CameraSourceTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.google.inject.Guice;
88
import com.google.inject.Injector;
99
import edu.wpi.grip.core.GRIPCoreModule;
10+
import edu.wpi.grip.core.events.StopPipelineEvent;
1011
import edu.wpi.grip.core.events.UnexpectedThrowableEvent;
1112
import edu.wpi.grip.core.util.MockExceptionWitness;
1213
import org.bytedeco.javacpp.indexer.Indexer;
@@ -186,4 +187,11 @@ public void testStartingTwiceShouldThrowIllegalState() throws Exception {
186187
fail("The test should have failed with an IllegalStateException");
187188
}
188189

190+
191+
@Test
192+
public void testStopPipelineEventDoesntThrowWhenCameraStopped() throws Exception {
193+
cameraSourceWithMockGrabber.onStopPipeline(new StopPipelineEvent());
194+
assertFalse("The camera source should not be running", cameraSourceWithMockGrabber.isStarted());
195+
}
196+
189197
}

0 commit comments

Comments
 (0)