Skip to content

Switching camera focus mode from "locked" to "auto" on android crashes #169985

Open
@2math

Description

@2math

Steps to reproduce

When I set focus mode from locked to auto on android it crashes with null pointer exception.
Setting the mode from auto to locked is OK.
On iOS is fine. I'm testing with Pixel 6(Android 15).

camera: ^0.11.1

Expected results

Expecting not to crash :)

Actual results

It crashes

Code sample

Code sample
void _initCamera() {
    cameraController!.initialize().then((_) {
      Log.d("camera init", tag);

      cameraController!.setFocusMode(FocusMode.locked);

      add(ControllerInitialized(cameraController));
    }, onError: (error) async {
      Log.error("camera init", error: error);
    });
  }

///When this function is called with FocusMode.locked is ok, for FocusMode.auto it crashes on android
Future<bool> setFocusMode(FocusMode mode) async{
    try {
      await cameraController!.setFocusMode(mode);
      add(OnFocusMode(mode));
      return true;
    } catch (e) {
      Log.error("setFocusMode $mode", error: e, tag: tag);
      return false;
    }
  }

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
I/flutter ( 6451): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 6451): │ Null check operator used on a null value
I/flutter ( 6451): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 6451): │ #0   AndroidCameraCameraX.setFocusMode (package:camera_android_camerax/src/android_camera_camerax.dart:636:41)
I/flutter ( 6451): │ #1   CameraController.setFocusMode (package:camera/src/camera_controller.dart:829:37)
I/flutter ( 6451): │ #2   CameraBloc.setFocusMode (package:Zoef/ui/camera/default_camera/bloc/camera_bloc.dart:144:31)
I/flutter ( 6451): │ #3   <asynchronous suspension>
I/flutter ( 6451): │ #4   _CameraFormState._buttonsRow.<anonymous closure> (package:Zoef/ui/camera/default_camera/camera_screen.dart:304:32)
I/flutter ( 6451): │ #5   <asynchronous suspension>
I/flutter ( 6451): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 6451): │ ⛔ 2025-06-04 15:31:21.587591 ERROR AppLog CameraBloc : setFocusMode FocusMode.auto 
I/flutter ( 6451): │ ⛔  Null check operator used on a null value
I/flutter ( 6451): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Flutter Doctor output

Doctor output
D:\code\flutter\futirists_git\freelap\.fvm\flutter_sdk\bin\flutter.bat doctor --verbose
[!] Flutter (Channel stable, 3.27.3, on Microsoft Windows [Version 10.0.26100.4061], locale bg-BG)
    • Flutter version 3.27.3 on channel stable at D:\code\flutter\futirists_git\freelap\.fvm\flutter_sdk
    ! Warning: `flutter` on your path resolves to D:\code\flutter\alieses\flutter.bat, which is not inside your current Flutter SDK checkout at D:\code\flutter\futirists_git\freelap\.fvm\flutter_sdk. Consider adding D:\code\flutter\futirists_git\freelap\.fvm\flutter_sdk\bin to the front of your path.
    ! Warning: `dart` on your path resolves to D:\code\flutter\alieses\dart.bat, which is not inside your current Flutter SDK checkout at D:\code\flutter\futirists_git\freelap\.fvm\flutter_sdk. Consider adding D:\code\flutter\futirists_git\freelap\.fvm\flutter_sdk\bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c519ee916e (4 months ago), 2025-01-21 10:32:23 -0800
    • Engine revision e672b006cb
    • Dart version 3.6.1
    • DevTools version 2.40.2
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
    • Android SDK at C:\Users\X\AppData\Local\Android\sdk
    • Platform android-35, build-tools 35.0.1
    • Java binary at: D:\code\soft2\studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.11.1)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.11.35219.272
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2024.1)
    • Android Studio at D:\code\soft2\studio
    • 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 17.0.11+0--11852314)

[√] Android Studio (version 2024.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 21.0.5+-13047016-b750.29)

[√] VS Code (version 1.96.4)
    • VS Code at C:\Users\X\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
       https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (4 available)
    • Pixel 6 (mobile)  • 18211FDF600140 • android-arm64  • Android 15 (API 35)
    • Windows (desktop) • windows        • windows-x64    • Microsoft Windows [Version 10.0.26100.4061]
    • Chrome (web)      • chrome         • web-javascript • Google Chrome 137.0.7151.56
    • Edge (web)        • edge           • web-javascript • Microsoft Edge 137.0.3296.52

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.
Process finished with exit code 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    in triagePresently being triaged by the triage teamwaiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions