From ebc177251d5980a7351c7aa8371902cace5c63b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Carballo?= Date: Tue, 4 Oct 2016 03:19:12 +0100 Subject: [PATCH] Fixes crash after accepting permission dialog (#23) * Fixes google/cameraview#1 - Camera crashes after accepting permission dialog * Update try catch style --- .../main/api21/com/google/android/cameraview/Camera2.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/src/main/api21/com/google/android/cameraview/Camera2.java b/library/src/main/api21/com/google/android/cameraview/Camera2.java index c3df1c10..053efba3 100644 --- a/library/src/main/api21/com/google/android/cameraview/Camera2.java +++ b/library/src/main/api21/com/google/android/cameraview/Camera2.java @@ -98,6 +98,8 @@ public void onConfigured(@NonNull CameraCaptureSession session) { mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback, null); } catch (CameraAccessException e) { + Log.e(TAG, "Failed to start camera preview because it couldn't access camera", e); + } catch (IllegalStateException e) { Log.e(TAG, "Failed to start camera preview.", e); } } @@ -109,7 +111,9 @@ public void onConfigureFailed(@NonNull CameraCaptureSession session) { @Override public void onClosed(@NonNull CameraCaptureSession session) { - mCaptureSession = null; + if (mCaptureSession != null && mCaptureSession.equals(session)) { + mCaptureSession = null; + } } };