mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2025-11-05 11:56:37 +00:00
prevent double free when closing capture library
This commit is contained in:
parent
a94380e882
commit
73d4fd5049
2 changed files with 8 additions and 7 deletions
|
|
@ -31,7 +31,6 @@ import com.sparrowwallet.sparrow.io.Config;
|
||||||
import com.sparrowwallet.sparrow.io.bbqr.BBQRDecoder;
|
import com.sparrowwallet.sparrow.io.bbqr.BBQRDecoder;
|
||||||
import com.sparrowwallet.sparrow.io.bbqr.BBQRException;
|
import com.sparrowwallet.sparrow.io.bbqr.BBQRException;
|
||||||
import com.sparrowwallet.sparrow.wallet.KeystoreController;
|
import com.sparrowwallet.sparrow.wallet.KeystoreController;
|
||||||
import io.reactivex.Observable;
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.property.DoubleProperty;
|
import javafx.beans.property.DoubleProperty;
|
||||||
import javafx.beans.property.ObjectProperty;
|
import javafx.beans.property.ObjectProperty;
|
||||||
|
|
@ -58,7 +57,6 @@ import java.nio.charset.CharsetDecoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
@ -203,8 +201,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||||
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
webcamResolutionProperty.set(null);
|
webcamResolutionProperty.set(null);
|
||||||
Observable.just(this).delay(500, TimeUnit.MILLISECONDS)
|
webcamService.close();
|
||||||
.subscribe(_ -> webcamService.close(), throwable -> log.error("Error closing webcam", throwable));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ public class WebcamService extends ScheduledService<Image> {
|
||||||
|
|
||||||
private final Semaphore taskSemaphore = new Semaphore(1);
|
private final Semaphore taskSemaphore = new Semaphore(1);
|
||||||
private final AtomicBoolean cancelRequested = new AtomicBoolean(false);
|
private final AtomicBoolean cancelRequested = new AtomicBoolean(false);
|
||||||
|
private final AtomicBoolean captureClosed = new AtomicBoolean(false);
|
||||||
|
|
||||||
private List<CaptureDevice> devices;
|
private List<CaptureDevice> devices;
|
||||||
private List<CaptureDevice> availableDevices;
|
private List<CaptureDevice> availableDevices;
|
||||||
|
|
@ -112,7 +113,7 @@ public class WebcamService extends ScheduledService<Image> {
|
||||||
return new Task<>() {
|
return new Task<>() {
|
||||||
@Override
|
@Override
|
||||||
protected Image call() throws Exception {
|
protected Image call() throws Exception {
|
||||||
if(cancelRequested.get() || isCancelled()) {
|
if(cancelRequested.get() || isCancelled() || captureClosed.get()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -264,9 +265,12 @@ public class WebcamService extends ScheduledService<Image> {
|
||||||
return cancelled;
|
return cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public synchronized void close() {
|
||||||
|
if(!captureClosed.get()) {
|
||||||
|
captureClosed.set(true);
|
||||||
capture.close();
|
capture.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public PropertyLimits getZoomLimits() {
|
public PropertyLimits getZoomLimits() {
|
||||||
return zoomLimits;
|
return zoomLimits;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue