File tree Expand file tree Collapse file tree 2 files changed +8
-7
lines changed
src/main/java/com/sparrowwallet/sparrow/control Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Original file line number Diff line number Diff line change 3131import com .sparrowwallet .sparrow .io .bbqr .BBQRDecoder ;
3232import com .sparrowwallet .sparrow .io .bbqr .BBQRException ;
3333import com .sparrowwallet .sparrow .wallet .KeystoreController ;
34- import io .reactivex .Observable ;
3534import javafx .application .Platform ;
3635import javafx .beans .property .DoubleProperty ;
3736import javafx .beans .property .ObjectProperty ;
5857import java .nio .charset .StandardCharsets ;
5958import java .util .*;
6059import java .util .List ;
61- import java .util .concurrent .TimeUnit ;
6260import java .util .regex .Matcher ;
6361import java .util .regex .Pattern ;
6462import java .util .stream .Collectors ;
@@ -203,8 +201,7 @@ public QRScanDialog() {
203201
204202 Platform .runLater (() -> {
205203 webcamResolutionProperty .set (null );
206- Observable .just (this ).delay (500 , TimeUnit .MILLISECONDS )
207- .subscribe (_ -> webcamService .close (), throwable -> log .error ("Error closing webcam" , throwable ));
204+ webcamService .close ();
208205 });
209206 });
210207
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ public class WebcamService extends ScheduledService<Image> {
3939
4040 private final Semaphore taskSemaphore = new Semaphore (1 );
4141 private final AtomicBoolean cancelRequested = new AtomicBoolean (false );
42+ private final AtomicBoolean captureClosed = new AtomicBoolean (false );
4243
4344 private List <CaptureDevice > devices ;
4445 private List <CaptureDevice > availableDevices ;
@@ -112,7 +113,7 @@ public Task<Image> createTask() {
112113 return new Task <>() {
113114 @ Override
114115 protected Image call () throws Exception {
115- if (cancelRequested .get () || isCancelled ()) {
116+ if (cancelRequested .get () || isCancelled () || captureClosed . get () ) {
116117 return null ;
117118 }
118119
@@ -264,8 +265,11 @@ public boolean cancel() {
264265 return cancelled ;
265266 }
266267
267- public void close () {
268- capture .close ();
268+ public synchronized void close () {
269+ if (!captureClosed .get ()) {
270+ captureClosed .set (true );
271+ capture .close ();
272+ }
269273 }
270274
271275 public PropertyLimits getZoomLimits () {
You can’t perform that action at this time.
0 commit comments