diff --git a/packages/camera/camera_android/CHANGELOG.md b/packages/camera/camera_android/CHANGELOG.md index e5e99ce82838..fc2a9fab44d0 100644 --- a/packages/camera/camera_android/CHANGELOG.md +++ b/packages/camera/camera_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.10.10+3 + +* Fixes thread race condition when closing the camera. + ## 0.10.10+2 * Don't set the FPS range unless video recording. It can cause dark image previews on some devices becuse the auto exposure algorithm is more constrained after fixing the min/max FPS range to the same value. This change has the side effect that providing the `fps` parameter will not affect the camera preview when not video recording. And if you need a lower frame rate in your image streaming handler, you can skip frames by checking the time it passed since the last frame. diff --git a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/Camera.java b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/Camera.java index 9b5aa049b445..c8530e973c52 100644 --- a/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/Camera.java +++ b/packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/Camera.java @@ -1293,10 +1293,12 @@ void setImageStreamImageAvailableListener(final EventChannel.EventSink imageStre } void closeCaptureSession() { - if (captureSession != null) { + // Keep a local copy to avoid race conditions between threads. + final CameraCaptureSession captureSessionToClose = captureSession; + if (captureSessionToClose != null) { Log.i(TAG, "closeCaptureSession"); - captureSession.close(); + captureSessionToClose.close(); captureSession = null; } } @@ -1324,8 +1326,10 @@ public void close() { } private void stopAndReleaseCamera() { - if (cameraDevice != null) { - cameraDevice.close(); + // Keep a local copy to avoid race conditions between threads. + final CameraDeviceWrapper cameraDeviceToClose = cameraDevice; + if (cameraDeviceToClose != null) { + cameraDeviceToClose.close(); cameraDevice = null; // Closing the CameraDevice without closing the CameraCaptureSession is recommended diff --git a/packages/camera/camera_android/pubspec.yaml b/packages/camera/camera_android/pubspec.yaml index f813858fd620..57d7f45f52da 100644 --- a/packages/camera/camera_android/pubspec.yaml +++ b/packages/camera/camera_android/pubspec.yaml @@ -3,7 +3,7 @@ description: Android implementation of the camera plugin. repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.10.10+2 +version: 0.10.10+3 environment: sdk: ^3.6.0