From 2b69888fbdf35b9804ceefcee1237427ae51d2f6 Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 28 Dec 2018 17:09:36 +0100 Subject: [PATCH] NPE when releasing camera fixed --- .../com/bobekos/bobek/scanner/scanner/BarcodeScanner.kt | 2 +- .../main/java/com/bobekos/bobek/scanner/scanner/Camera.kt | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/scanner/src/main/java/com/bobekos/bobek/scanner/scanner/BarcodeScanner.kt b/scanner/src/main/java/com/bobekos/bobek/scanner/scanner/BarcodeScanner.kt index b98c79f..9dbc348 100644 --- a/scanner/src/main/java/com/bobekos/bobek/scanner/scanner/BarcodeScanner.kt +++ b/scanner/src/main/java/com/bobekos/bobek/scanner/scanner/BarcodeScanner.kt @@ -59,7 +59,7 @@ internal class BarcodeScanner( emitter.setCancellable { updateDisposable?.dispose() - camera.getCameraSource()?.release() + camera.releaseCameraSource() } updateDisposable = updateSubject.subscribe({ camera.setParametersFromConfig() }, {}) diff --git a/scanner/src/main/java/com/bobekos/bobek/scanner/scanner/Camera.kt b/scanner/src/main/java/com/bobekos/bobek/scanner/scanner/Camera.kt index 3807df7..e7aa0f9 100644 --- a/scanner/src/main/java/com/bobekos/bobek/scanner/scanner/Camera.kt +++ b/scanner/src/main/java/com/bobekos/bobek/scanner/scanner/Camera.kt @@ -97,4 +97,10 @@ internal class Camera(private val ctx: Context?, private val config: BarcodeScan return cameraSource } + fun releaseCameraSource() { + try { + cameraSource?.release() + } catch (ignored: NullPointerException) { + } + } } \ No newline at end of file