Skip to content

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

@SherpaMiguel

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!

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