Skip to content

Commit

Permalink
ConcurrentModificationException in Webcam.dispose(), fixes #122
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Jul 20, 2013
1 parent 8ad295d commit 23653cd
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -75,7 +77,7 @@ public class Webcam {
/**
* Webcam listeners.
*/
private List<WebcamListener> listeners = Collections.synchronizedList(new ArrayList<WebcamListener>());
private List<WebcamListener> listeners = new CopyOnWriteArrayList<WebcamListener>();

/**
* List of custom resolution sizes supported by webcam instance.
Expand Down Expand Up @@ -213,7 +215,11 @@ public boolean open(boolean async) {
// notify listeners

WebcamEvent we = new WebcamEvent(WebcamEventType.OPEN, this);
for (WebcamListener l : getWebcamListeners()) {
Iterator<WebcamListener> wli = listeners.iterator();
WebcamListener l = null;

while (wli.hasNext()) {
l = wli.next();
try {
l.webcamOpen(we);
} catch (Exception e) {
Expand Down Expand Up @@ -269,7 +275,11 @@ public boolean close() {
// notify listeners

WebcamEvent we = new WebcamEvent(WebcamEventType.CLOSED, this);
for (WebcamListener l : getWebcamListeners()) {
Iterator<WebcamListener> wli = listeners.iterator();
WebcamListener l = null;

while (wli.hasNext()) {
l = wli.next();
try {
l.webcamClosed(we);
} catch (Exception e) {
Expand Down Expand Up @@ -325,7 +335,11 @@ protected void dispose() {
}

WebcamEvent we = new WebcamEvent(WebcamEventType.DISPOSED, this);
for (WebcamListener l : listeners) {
Iterator<WebcamListener> wli = listeners.iterator();
WebcamListener l = null;

while (wli.hasNext()) {
l = wli.next();
try {
l.webcamClosed(we);
l.webcamDisposed(we);
Expand Down

0 comments on commit 23653cd

Please sign in to comment.