Skip to content

Commit

Permalink
Make sure the capture thread gets terminated
Browse files Browse the repository at this point in the history
  • Loading branch information
RetGal committed Dec 15, 2024
1 parent afa6255 commit 26681d3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/mpo/dayon/assisted/capture/CaptureEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ public class CaptureEngine implements ReConfigurable<CaptureEngineConfiguration>

private boolean reconfigured;

private boolean running;

public CaptureEngine(CaptureFactory captureFactory) {
this.captureFactory = captureFactory;
this.captureDimension = captureFactory.getDimension();
final int x = (captureDimension.width + TILE_DIMENSION.width -1) / TILE_DIMENSION.width;
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
Expand Down Expand Up @@ -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() {
Expand All @@ -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 (!)
Expand Down

0 comments on commit 26681d3

Please sign in to comment.