From 94c5920c27d38f123d4f1b025e1463816c9ec11a Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 11 Jul 2022 14:13:49 +0200 Subject: [PATCH] prevent potential npe on qr display dialog --- .../sparrow/control/QRDisplayDialog.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/QRDisplayDialog.java b/src/main/java/com/sparrowwallet/sparrow/control/QRDisplayDialog.java index 8fcd4ccf..afd0c21f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/QRDisplayDialog.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/QRDisplayDialog.java @@ -78,12 +78,7 @@ public class QRDisplayDialog extends Dialog { if(encoder.isSinglePart()) { qrImageView.setImage(getQrCode(currentPart)); } else { - animateQRService = new AnimateQRService(); - animateQRService.setPeriod(Duration.millis(ANIMATION_PERIOD_MILLIS)); - animateQRService.start(); - setOnCloseRequest(event -> { - animateQRService.cancel(); - }); + createAnimateQRService(); } final ButtonType cancelButtonType = new javafx.scene.control.ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE); @@ -124,6 +119,15 @@ public class QRDisplayDialog extends Dialog { setResultConverter(dialogButton -> dialogButton != cancelButtonType ? ur : null); } + private void createAnimateQRService() { + animateQRService = new AnimateQRService(); + animateQRService.setPeriod(Duration.millis(ANIMATION_PERIOD_MILLIS)); + animateQRService.start(); + setOnCloseRequest(event -> { + animateQRService.cancel(); + }); + } + private void nextPart() { if(!useLegacyEncoding) { String fragment = encoder.nextPart(); @@ -169,6 +173,8 @@ public class QRDisplayDialog extends Dialog { nextPart(); qrImageView.setImage(getQrCode(currentPart)); + } else if(animateQRService == null) { + createAnimateQRService(); } else if(!animateQRService.isRunning()) { animateQRService.reset(); animateQRService.start(); @@ -185,6 +191,8 @@ public class QRDisplayDialog extends Dialog { } qrImageView.setImage(getQrCode(currentPart)); + } else if(animateQRService == null) { + createAnimateQRService(); } else if(!animateQRService.isRunning()) { animateQRService.reset(); animateQRService.start();