File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
webcam-capture/src/main/java/com/github/sarxos/webcam Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -283,6 +283,20 @@ public boolean open(boolean async) {
283283
284284 LOG .debug ("Webcam is now open {}" , getName ());
285285
286+ // install shutdown hook
287+
288+ try {
289+ Runtime .getRuntime ().addShutdownHook (hook = new WebcamShutdownHook (this ));
290+ } catch (IllegalStateException e ) {
291+
292+ LOG .debug ("Shutdown in progress, do not open device" );
293+ LOG .trace (e .getMessage (), e );
294+
295+ close ();
296+
297+ return false ;
298+ }
299+
286300 // setup non-blocking configuration
287301
288302 if (asynchronous = async ) {
@@ -292,10 +306,6 @@ public boolean open(boolean async) {
292306 updater .start ();
293307 }
294308
295- // install shutdown hook
296-
297- Runtime .getRuntime ().addShutdownHook (hook = new WebcamShutdownHook (this ));
298-
299309 // notify listeners
300310
301311 WebcamEvent we = new WebcamEvent (WebcamEventType .OPEN , this );
You can’t perform that action at this time.
0 commit comments