diff --git a/src/main/java/mpo/dayon/assisted/capture/CaptureEngine.java b/src/main/java/mpo/dayon/assisted/capture/CaptureEngine.java index 38a3c127..f3a63368 100644 --- a/src/main/java/mpo/dayon/assisted/capture/CaptureEngine.java +++ b/src/main/java/mpo/dayon/assisted/capture/CaptureEngine.java @@ -43,6 +43,8 @@ public class CaptureEngine implements ReConfigurable private boolean reconfigured; + private boolean running; + public CaptureEngine(CaptureFactory captureFactory) { this.captureFactory = captureFactory; this.captureDimension = captureFactory.getDimension(); @@ -50,6 +52,7 @@ public CaptureEngine(CaptureFactory captureFactory) { final int y = (captureDimension.height + TILE_DIMENSION.height -1) / TILE_DIMENSION.height; this.previousCapture = new long[x * y]; resetPreviousCapture(); + running = true; this.thread = new Thread(new RunnableEx() { @Override @@ -83,12 +86,19 @@ public void addListener(CaptureEngineListener listener) { public void start() { Log.debug("CaptureEngine start"); + running = true; thread.start(); } public void stop() { Log.debug("CaptureEngine stop"); + running = false; thread.interrupt(); + try { + thread.join(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } } private void mainLoop() { @@ -101,7 +111,7 @@ private void mainLoop() { int skipped = 0; AtomicBoolean reset = new AtomicBoolean(false); - while (true) { + while (running) { synchronized (reconfigurationLOCK) { if (reconfigured) { // assuming everything has changed (!)