Skip to content

[camera_avfoundation] Crash when opening camera stream starting from 0.9.19+2 #170240

Description

@SherpaMiguel

Steps to reproduce

  1. Run the camera example app on physical device (reproduced on iPhone 12, 15 Pro Max, 16 Pro)
  2. Select a camera
  3. Start stream
  4. Camera crashes with "Unsupported value: (Function) of type __SwiftValue" error

Expected results

Stream opens normally

Actual results

Unsupported value: (Function) of type __SwiftValue

0.9.19+1 version works as expected

Code sample

Code sample
import 'package:camera/camera.dart';
import 'package:flutter/foundation.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

final scanController = StateNotifierProvider.autoDispose<ScanController, CameraStatus>(
  (ref) => ScanController(),
);

class ScanController extends StateNotifier<CameraStatus> {
  CameraController? _cameraController;
  CameraDescription? _camera;
  CameraController? get cameraController => _cameraController;
  ScanController() : super(CameraStatus.off); // Estado inicial de la cámara

  Future initCamera() async {
    try {
      _camera = (await availableCameras()).firstOrNull;
      if (_camera == null) {
        debugPrint('No camera available');
        return;
      }
      _cameraController = CameraController(_camera!, ResolutionPreset.high, enableAudio: false);

      // Inicializar cámara
      _cameraController!.initialize().then((_) async {
        if (!mounted) return;
        await _cameraController!.startImageStream((image) {});
      }).catchError((_) {
        _cameraController?.dispose();
      });
    } on CameraException catch (e) {
      debugPrint('Error iniciando cámara: ${e.description}');
    } catch (e) {
      debugPrint('Error iniciando cámara: $e');
    }
  }
}

enum CameraStatus {
  off, // Estado inicial. La cámara no está preparada para capturar imagen.
  ready, // La cámara está lista para capturar imagen y a la espera.
}

import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class ScanScreen extends ConsumerWidget {
  const ScanScreen({super.key});

  static String get routeName => 'scan';

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final controller = ref.watch(scanController.notifier);

    WidgetsBinding.instance.addPostFrameCallback((_) => controller.initCamera());

    final cameraController = controller.cameraController;
    final isCameraInitialized = cameraController?.value.isInitialized == true;

    if (!isCameraInitialized) {
      return const Center(child: CircularProgressIndicator());
    }

    return Scaffold(body: Center(child: CameraPreview(cameraController!)));
  }
}

Screenshots or Video

Screenshots / Video demonstration Image

Logs

Logs
<<<< FigCaptureSessionRemote >>>> Fig assert: "err == 0 " at bail (FigCaptureSessionRemote.m:855) - (err=-12784)
Unsupported value: (Function) of type __SwiftValue
*** Assertion failure in void WriteValueOfType(CFTypeRef, CFMutableDataRef, FlutterStandardCodecObjcType, CFTypeRef)(), FlutterStandardCodec.mm:341
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unsupported value for standard codec'
*** First throw call stack:
(0x19ca792ec 0x199efda7c 0x19bd76040 0x10e977ad4 0x10e97775c 0x19b332c5c 0x19b0b7c4c 0x19c9d984c 0x10e977be8 0x10e97775c 0x10e9789a4 0x10e9742a8 0x10481fa78 0x10481fadc 0x10481a184 0x105448584 0x105462064 0x105482f38 0x105458548 0x105458484 0x19c9d22b4 0x19c9d00b0 0x19c9f4700 0x1e9535190 0x19f612240 0x19f610470 0x19fa6ea30 0x1079a5188 0x1079a50f8 0x1079a5204 0x1c33f7ad8)
libc++abi: terminating due to uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unsupported value for standard codec'
*** First throw call stack:
(0x19ca792ec 0x199efda7c 0x19bd76040 0x10e977ad4 0x10e97775c 0x19b332c5c 0x19b0b7c4c 0x19c9d984c 0x10e977be8 0x10e97775c 0x10e9789a4 0x10e9742a8 0x10481fa78 0x10481fadc 0x10481a184 0x105448584 0x105462064 0x105482f38 0x105458548 0x105458484 0x19c9d22b4 0x19c9d00b0 0x19c9f4700 0x1e9535190 0x19f612240 0x19f610470 0x19fa6ea30 0x1079a5188 0x1079a50f8 0x1079a5204 0x1c33f7ad8)
terminating due to uncaught exception of type NSException

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.32.2, on macOS 15.5 24F74 darwin-arm64, locale es-ES) [252ms]
    • Flutter version 3.32.2 on channel stable at /Users/miguel/bin/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 8defaa71a7 (5 days ago), 2025-06-04 11:02:51 -0700
    • Engine revision 1091508939
    • Dart version 3.8.1
    • DevTools version 2.45.1

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [1.117ms]
    • Android SDK at /Users/miguel/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.4) [694ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16F6
    • CocoaPods version 1.16.2

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

[✓] Android Studio (version 2024.2) [9ms]
    • Android Studio at /Applications/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 21.0.5+-12932927-b750.29)

[✓] VS Code (version 1.100.3) [9ms]
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.56.0

[✓] Connected device (3 available) [5,8s]

[✓] Network resources [284ms]
    • All expected network resources are available.

• No issues found!

Activity

  1. changed the title [-][camera_avfoundation] Crash when opening camera stream from 0.9.19+2[/-] [+][camera_avfoundation] Crash when opening camera stream starting from 0.9.19+2[/+] on Jun 9, 2025
  2. darshankawar commented on Jun 10, 2025

    @darshankawar
    Member

    @SherpaMiguel Thanks for the report. I am unable to replicate this after running the camera example on iPhone 15 device. What device does it throw the error on ? Also, can you provide the complete error log ?

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jun 10, 2025
  4. SherpaMiguel commented on Jun 10, 2025

    @SherpaMiguel
    Author

    @darshankawar I have updated the description with some logs and a screenshot in Xcode. Also added an example (sorry, I use riverpod). Also note that issue occurs on iPhone 12, 15 Pro Max, 16 Pro.

    Thank you in advance.

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jun 10, 2025
  6. Deehodry-dhj commented on Jun 10, 2025

    @Deehodry-dhj
  7. Deehodry-dhj commented on Jun 11, 2025

    @Deehodry-dhj
  8. darshankawar commented on Jun 11, 2025

    @darshankawar
    Member

    Thanks for the update. This error is replicable without using riverpod as well, which throws below error log:

    -- LLDB integration loaded --
    fopen failed for data file: errno = 2 (No such file or directory)
    Errors found! Invalidating cache...
    flutter: The Dart VM service is listening on http://0.0.0.0:62461/uTZxX8QABqM=/
    fopen failed for data file: errno = 2 (No such file or directory)
    Errors found! Invalidating cache...
    FlutterView implements focusItemsInRect: - caching for linear focus movement is limited as long as this view is on screen.
    This FlutterEngine was already invoked.
    Unsupported value: (Function) of type __SwiftValue
    *** Assertion failure in void WriteValueOfType(CFTypeRef, CFMutableDataRef, FlutterStandardCodecObjcType, CFTypeRef)(), FlutterStandardCodec.mm:341
    *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unsupported value for standard codec'
    *** First throw call stack:
    (0x18d26c7cc 0x18a53f2e4 0x18c63ca78 0x108211cc4 0x10821194c 0x18bb866e4 0x18b8e0168 0x18d26b5f4 0x108211dd8 0x10821194c 0x108212b94 0x10820e4c8 0x1054b35d4 0x1054b37dc 0x1054a0a1c 0x105538a30 0x10553a71c 0x10554ade8 0x10554a9a4 0x18d240204 0x18d23d440 0x18d23c830 0x1d921c1c4 0x18fda2eb0 0x18fe515b4 0x19018bfa8 0x104a68584 0x104a684fc 0x104a68600 0x1b2c2aec8)
    libc++abi: terminating due to uncaught exception of type NSException
    

    Verified upto camera: ^0.11.0 which throws the same error as above. Per OP, this worked in 0.9.19+1 so labeling this as regression.

    stable : 3.32.2
    master : 3.33.0-1.0.pre.444
    
  9. added
    packageflutter/packages repository. See also p: labels.
    c: crashStack traces logged to the console
    platform-iosiOS applications specifically
    c: regressionIt was better in the past than it is now
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    on Jun 11, 2025
  10. 16 remaining items

  11. knottx commented on Jun 16, 2025

    @knottx
  12. ethicnology commented on Jun 16, 2025

    @ethicnology

    I can confirm the issue disappears with the following override: camera_avfoundation: 0.9.19+1
    My setup: flutter: 3.32.3, channel: stable camera: 0.11.1 Device: iOS 15 Pro iOS 18.5 (22F76)

    You can also override the dependency version directly in your pubspec.yaml file using dependency_overrides:

    dependency_overrides:
      camera_avfoundation: 0.9.19+1
  13. knottx commented on Jun 18, 2025

    @knottx
  14. hellohuanlin commented on Jun 18, 2025

    @hellohuanlin
    Contributor

    This should be resolved after flutter/packages#9418 is landed.

  15. Osmosis311 commented on Jun 18, 2025

    @Osmosis311

    Thanks! What version will this end up in?

  16. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jun 19, 2025
  17. RobertOdrowaz commented on Jun 20, 2025

    @RobertOdrowaz
    Contributor

    @Osmosis311 It is in the camera_avfoundation 0.9.20. If you want to ensure you're using the fixed version, you can either explicitly add a constraint for camera_avfoundation to your pubspec.yaml or make sure you depend on the 0.9.20 version in pubspec.lock

  18. github-actions commented on Jul 4, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  19. locked as resolved and limited conversation to collaborators on Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c: crashStack traces logged to the consolec: regressionIt was better in the past than it is nowfound in release: 3.32Found to occur in 3.32found in release: 3.33Found to occur in 3.33has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: cameraThe camera pluginpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-iosOwned by iOS platform team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions