Skip to content

[Camera] CameraController.takePicture() crashes due to Unconfigured Input/Output Surface #125314

@MILLT189

Description

@MILLT189

Is there an existing issue for this?

Steps to reproduce

  1. Using the example code for Camera as inspiration, create a camera example app in Flutter
  2. Request the camera hardware info, using cameras = await availableCameras();
  3. Create a camera controller, using something like this:
    cameraController = CameraController( cameraDescription!, cameraResolutionPresetSelected, enableAudio: false, imageFormatGroup: imageFormatGroup, );
  4. Initialize the camera, using await cameraController!.initialize();
  5. Observe camera preview working as intended
  6. Attempt to take a picture by calling the Camera plugin's cameraController.takePicture()
  7. A crash stops the application with this stacktrace:

E/AndroidRuntime(25340): Process: com.disney.mobile_chassis_camera.mobile_chassis_camera_example, PID: 25340 E/AndroidRuntime(25340): java.lang.IllegalArgumentException: CaptureRequest contains unconfigured Input/Output Surface! E/AndroidRuntime(25340): at android.hardware.camera2.CaptureRequest.convertSurfaceToStreamId(CaptureRequest.java:765) E/AndroidRuntime(25340): at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:1289) E/AndroidRuntime(25340): at android.hardware.camera2.impl.CameraDeviceImpl.capture(CameraDeviceImpl.java:1126) E/AndroidRuntime(25340): at android.hardware.camera2.impl.CameraCaptureSessionImpl.capture(CameraCaptureSessionImpl.java:189) E/AndroidRuntime(25340): at io.flutter.plugins.camera.Camera.takePictureAfterPrecapture(Camera.java:663) E/AndroidRuntime(25340): at io.flutter.plugins.camera.Camera.onConverged(Camera.java:225) E/AndroidRuntime(25340): at io.flutter.plugins.camera.CameraCaptureCallback.process(CameraCaptureCallback.java:135) E/AndroidRuntime(25340): at io.flutter.plugins.camera.CameraCaptureCallback.onCaptureProgressed(CameraCaptureCallback.java:161) E/AndroidRuntime(25340): at android.hardware.camera2.impl.CameraCaptureSessionImpl$1.lambda$onCaptureProgressed$2$android-hardware-camera2-impl-CameraCaptureSessionImpl$1(CameraCaptureSessionImpl.java:679) E/AndroidRuntime(25340): at android.hardware.camera2.impl.CameraCaptureSessionImpl$1$$ExternalSyntheticLambda0.run(Unknown Source:8) E/AndroidRuntime(25340): at android.os.Handler.handleCallback(Handler.java:942) E/AndroidRuntime(25340): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(25340): at android.os.Looper.loopOnce(Looper.java:226) E/AndroidRuntime(25340): at android.os.Looper.loop(Looper.java:313) E/AndroidRuntime(25340): at android.os.HandlerThread.run(HandlerThread.java:67) I/flutter (25340): mobile_chassis_camera - AppLifecycleState: AppLifecycleState.inactive I/flutter (25340): mobile_chassis_camera - onDidChangeAppLifecycleState - state: AppLifecycleState.inactive I/flutter (25340): mobile_chassis_camera - dismiss I/Process (25340): Sending signal. PID: 25340 SIG: 9 Lost connection to device.

The issue we experienced seems similar to this open bug:
#46082

Tested with a Galaxy S21 Ultra 5G (Android 13) device, using Camera version ^0.10.4

Expected results

CameraController.takePhoto() should work when it has been configured for our use.

Actual results

We cannot use or properly configure the Camera to take a photo.

Code sample

Use the official example, then attempt to take a photo.

https://github.com/flutter/packages/blob/main/packages/camera/camera/example/lib/readme_full_example.dart

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
I/flutter (25340): mobile_chassis_camera - capturePhoto
I/flutter (25340): mobile_chassis_camera - capturePhoto - attempting cameraController.takePicture(). Camera controller: CameraController#c03c2(CameraValue(isRecordingVideo: false, isInitialized: true, errorDescription: null, previewSize: Size(1280.0, 720.0), isStreamingImages: true, flashMode: FlashMode.auto, exposureMode: ExposureMode.auto, focusMode: FocusMode.auto, exposurePointSupported: true, focusPointSupported: true, deviceOrientation: DeviceOrientation.portraitUp, lockedCaptureOrientation: null, recordingOrientation: null, isPreviewPaused: false, previewPausedOrientation: null, description: CameraDescription(0, CameraLensDirection.back, 90)))
I/flutter (25340): mobile_chassis_camera - onImageStreamPauseOrResume - should resume: false
I/Camera  (25340): startPreview
I/CameraManagerGlobal(25340): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_IDLE for client com.disney.mobile_chassis_camera.mobile_chassis_camera_example API Level 2
I/Camera  (25340): CameraCaptureSession onConfigured
I/Camera  (25340): Updating builder settings
W/_camera_example(25340): Long monitor contention with owner main (25340) at void android.hardware.camera2.impl.CameraDeviceImpl.waitUntilIdle()(CameraDeviceImpl.java:1402) waiters=0 in void android.hardware.camera2.impl.CameraDeviceImpl$4.run() for 428ms
...
W/_camera_example(25340): Long monitor contention with owner main (25340) at void android.hardware.camera2.impl.CameraDeviceImpl.waitUntilIdle()(CameraDeviceImpl.java:1402) waiters=1 in void android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.onResultReceived(android.hardware.camera2.impl.CameraMetadataNative, android.hardware.camera2.impl.CaptureResultExtras, android.hardware.camera2.impl.PhysicalCaptureResultInfo[]) for 429ms
I/Camera  (25340): runPictureAutoFocus
I/Camera  (25340): lockAutoFocus
I/CameraManagerGlobal(25340): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_ACTIVE for client com.disney.mobile_chassis_camera.mobile_chassis_camera_example API Level 2
D/CameraCaptureCallback(25340): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 2
D/CameraCaptureCallback(25340): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 2
D/CameraCaptureCallback(25340): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 2
D/CameraCaptureCallback(25340): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 2
D/CameraCaptureCallback(25340): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 2
D/CameraCaptureCallback(25340): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 2
D/CameraCaptureCallback(25340): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 2
D/CameraCaptureCallback(25340): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 2
D/CameraCaptureCallback(25340): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 2
D/CameraCaptureCallback(25340): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 2
D/CameraCaptureCallback(25340): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 2
I/Camera  (25340): CameraCaptureSession onClosed
W/System  (25340): A resource failed to call Surface.release. 
I/CameraManagerGlobal(25340): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_IDLE for client com.disney.mobile_chassis_camera.mobile_chassis_camera_example API Level 2
I/ViewRootImpl@c137711[MainActivity](25340): ViewPostIme pointer 0
I/ViewRootImpl@c137711[MainActivity](25340): ViewPostIme pointer 1
I/flutter (25340): mobile_chassis_camera - onCameraPreviewToggle toggled: true
I/flutter (25340): mobile_chassis_camera - onImageStreamPauseOrResume - should resume: true
I/Camera  (25340): CameraCaptureSession onClosed
I/Camera  (25340): startPreviewWithImageStream
I/Camera  (25340): CameraCaptureSession onConfigured
I/Camera  (25340): Updating builder settings
D/Camera  (25340): Updating builder with feature: ExposureLockFeature
D/Camera  (25340): Updating builder with feature: ExposurePointFeature
D/Camera  (25340): Updating builder with feature: ZoomLevelFeature
I/Camera  (25340): refreshPreviewCaptureSession
D/Camera  (25340): Updating builder with feature: AutoFocusFeature
W/_camera_example(25340): Long monitor contention with owner main (25340) at void android.hardware.camera2.impl.CameraDeviceImpl.waitUntilIdle()(CameraDeviceImpl.java:1402) waiters=0 in void android.hardware.camera2.impl.CameraDeviceImpl$4.run() for 282ms
D/Camera  (25340): Updating builder with feature: NoiseReductionFeature
I/Camera  (25340): updateNoiseReduction | currentSetting: fast
D/Camera  (25340): Updating builder with feature: FocusPointFeature
D/Camera  (25340): Updating builder with feature: ResolutionFeature
D/Camera  (25340): Updating builder with feature: SensorOrientationFeature
D/Camera  (25340): Updating builder with feature: FlashFeature
D/Camera  (25340): Updating builder with feature: ExposureOffsetFeature
D/Camera  (25340): Updating builder with feature: FpsRangeFeature
I/Camera  (25340): refreshPreviewCaptureSession
I/CameraManagerGlobal(25340): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_ACTIVE for client com.disney.mobile_chassis_camera.mobile_chassis_camera_example API Level 2
D/CameraCaptureCallback(25340): CameraCaptureCallback | state: STATE_WAITING_FOCUS | afState: 2 | aeState: 1
W/CameraCaptureCallback(25340): Focus timeout, moving on with capture
I/Camera  (25340): runPrecaptureSequence
I/Camera  (25340): refreshPreviewCaptureSession
D/CameraCaptureCallback(25340): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_START | afState: 2 | aeState: 1
W/CameraCaptureCallback(25340): Metering timeout waiting for pre-capture to start, moving on with capture
D/CameraCaptureCallback(25340): CameraCaptureCallback | state: STATE_WAITING_PRECAPTURE_DONE | afState: 2 | aeState: 1
I/Camera  (25340): captureStillPicture
D/Camera  (25340): Updating builder with feature: ExposureLockFeature
D/Camera  (25340): Updating builder with feature: ExposurePointFeature
D/Camera  (25340): Updating builder with feature: ZoomLevelFeature
D/Camera  (25340): Updating builder with feature: AutoFocusFeature
D/Camera  (25340): Updating builder with feature: NoiseReductionFeature
I/Camera  (25340): updateNoiseReduction | currentSetting: fast
D/Camera  (25340): Updating builder with feature: FocusPointFeature
D/Camera  (25340): Updating builder with feature: ResolutionFeature
D/Camera  (25340): Updating builder with feature: SensorOrientationFeature
D/Camera  (25340): Updating builder with feature: FlashFeature
D/Camera  (25340): Updating builder with feature: ExposureOffsetFeature
D/Camera  (25340): Updating builder with feature: FpsRangeFeature
I/Camera  (25340): sending capture request
E/AndroidRuntime(25340): FATAL EXCEPTION: CameraBackground
E/AndroidRuntime(25340): Process: com.disney.mobile_chassis_camera.mobile_chassis_camera_example, PID: 25340
E/AndroidRuntime(25340): java.lang.IllegalArgumentException: CaptureRequest contains unconfigured Input/Output Surface!
E/AndroidRuntime(25340):     at android.hardware.camera2.CaptureRequest.convertSurfaceToStreamId(CaptureRequest.java:765)
E/AndroidRuntime(25340):     at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:1289)
E/AndroidRuntime(25340):     at android.hardware.camera2.impl.CameraDeviceImpl.capture(CameraDeviceImpl.java:1126)
E/AndroidRuntime(25340):     at android.hardware.camera2.impl.CameraCaptureSessionImpl.capture(CameraCaptureSessionImpl.java:189)
E/AndroidRuntime(25340):     at io.flutter.plugins.camera.Camera.takePictureAfterPrecapture(Camera.java:663)
E/AndroidRuntime(25340):     at io.flutter.plugins.camera.Camera.onConverged(Camera.java:225)
E/AndroidRuntime(25340):     at io.flutter.plugins.camera.CameraCaptureCallback.process(CameraCaptureCallback.java:135)
E/AndroidRuntime(25340):     at io.flutter.plugins.camera.CameraCaptureCallback.onCaptureProgressed(CameraCaptureCallback.java:161)
E/AndroidRuntime(25340):     at android.hardware.camera2.impl.CameraCaptureSessionImpl$1.lambda$onCaptureProgressed$2$android-hardware-camera2-impl-CameraCaptureSessionImpl$1(CameraCaptureSessionImpl.java:679)
E/AndroidRuntime(25340):     at android.hardware.camera2.impl.CameraCaptureSessionImpl$1$$ExternalSyntheticLambda0.run(Unknown Source:8)
E/AndroidRuntime(25340):     at android.os.Handler.handleCallback(Handler.java:942)
E/AndroidRuntime(25340):     at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(25340):     at android.os.Looper.loopOnce(Looper.java:226)
E/AndroidRuntime(25340):     at android.os.Looper.loop(Looper.java:313)
E/AndroidRuntime(25340):     at android.os.HandlerThread.run(HandlerThread.java:67)
I/flutter (25340): mobile_chassis_camera - AppLifecycleState: AppLifecycleState.inactive
I/flutter (25340): mobile_chassis_camera - onDidChangeAppLifecycleState - state: AppLifecycleState.inactive
I/flutter (25340): mobile_chassis_camera - dismiss
I/Process (25340): Sending signal. PID: 25340 SIG: 9
Lost connection to device.

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.7.11, on macOS 12.6.4 21G526 darwin-x64, locale en-US)
    • Flutter version 3.7.11 on channel stable at /Users/Tyson.Miller/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f72efea43c (10 days ago), 2023-04-11 11:57:21 -0700
    • Engine revision 1a65d409c7
    • Dart version 2.19.6
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/Tyson.Miller/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • ANDROID_HOME = /Users/Tyson.Miller/Library/Android/sdk
    • ANDROID_SDK_ROOT = /Users/Tyson.Miller/Library/Android/sdk
    • Java binary at: /Users/Tyson.Miller/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android
      Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Users/Tyson.Miller/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android
      Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] Android Studio (version 2021.1)
    • Android Studio at /Users/Tyson.Miller/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/211.7628.21.2111.8309675/Android
      Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)

[✓] IntelliJ IDEA Community Edition (version 2022.3.1)
    • IntelliJ at /Users/Tyson.Miller/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/223.8214.52/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] IntelliJ IDEA Community Edition (version 2022.3)
    • IntelliJ at /Users/Tyson.Miller/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/223.7571.182/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.76.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.62.0

[✓] Connected device (1 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 112.0.5615.137

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listcustomer: castawayp: cameraThe camera pluginplatform-androidAndroid applications specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions