Skip to content

Commit

Permalink
Fix illegal state exception when closing application, fixes #97
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed May 10, 2013
1 parent fe92b50 commit 3a34bf9
Showing 1 changed file with 9 additions and 3 deletions.
Expand Up @@ -247,7 +247,7 @@ public boolean close() {

// remove shutdown hook (it's not more necessary)

Runtime.getRuntime().removeShutdownHook(hook);
removeShutdownHook();

// notify listeners

Expand Down Expand Up @@ -317,17 +317,23 @@ protected void dispose() {
}
}

removeShutdownHook();

LOG.debug("Webcam disposed {}", getName());
}

private void removeShutdownHook() {

// hook can be null because there is a possibility that webcam has never
// been open and therefore hook was not created

if (hook != null) {
try {
Runtime.getRuntime().removeShutdownHook(hook);
} catch (IllegalStateException e) {
LOG.trace("Shutdown in progress, cannot remove hook");
}
}

LOG.debug("Webcam disposed {}", getName());
}

/**
Expand Down

0 comments on commit 3a34bf9

Please sign in to comment.