Skip to content

[camera] startImageStream throws NSInternalInconsistencyException on iOS #170367

Closed as duplicate of#170240
@arthas1888

Description

@arthas1888

Steps to reproduce

Create a new Flutter App
Install camera package camera 0.11.1
Add the following in your Info.plist:
NSCameraUsageDescription
your usage description here
NSMicrophoneUsageDescription
your usage description here
Use the code below as your main.dart

Expected results

You should see "STREAM" printed to the console on each run, but the exception occurs before

Actual results

This is the exact error I see, when it actually occurs, when running the example code:

Unsupported value: (Function) of type __SwiftValue

// Lock the base address before accessing pixel data, and unlock it afterwards. // Done accessing the pixelBuffer` at this point.
CVPixelBufferUnlockBaseAddress(pixelBuffer, .readOnly)

    let imageBuffer: [String: Any] = [
      "width": imageWidth,
      "height": imageHeight,
      "format": videoFormat,
      "planes": planes,
      "lensAperture": captureDevice.lensAperture,
      "sensorExposureTime": NSNumber(
        value: captureDevice.exposureDuration().seconds * 1_000_000_000),
      "sensorSensitivity": NSNumber(value: captureDevice.iso()),
    ]

    DispatchQueue.main.async {
      eventSink(imageBuffer) <- here  Thread 1: "Unsupported value for standard codec"
    }`

Code sample

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Cam issue',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  late CameraController controller;
  List<CameraDescription>? cameras;

  @override
  void initState() {
    loadCameras();
    super.initState();
  }

  loadCameras() async {
    try {
      cameras = await availableCameras();
      setState(() {});
    } on CameraException catch (e) {
      print('Error: ${e.code}\nError Message: ${e.description}');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Cam issue"),
      ),
      body: body(),
    );
  }

  body() {
    if (cameras?.isNotEmpty ?? false) {
      return Center(
        child: MyCameraPreview(cameras: cameras!),
      );
    }
    return const Center(
      child: Text("Loading"),
    );
  }
}

class MyCameraPreview extends StatefulWidget {
  final List<CameraDescription> cameras;

  const MyCameraPreview({
    Key? key,
    required this.cameras,
  }) : super(key: key);

  @override
  State<MyCameraPreview> createState() => _MyCameraPreviewState();
}

class _MyCameraPreviewState extends State<MyCameraPreview> {
  late CameraController controller;
  bool isDetecting = false;

  @override
  void initState() {
    initController();
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  Future<void> initController() async {
    controller = CameraController(
      widget.cameras[0],
      ResolutionPreset.high,
      enableAudio: false,
    );
    await controller.initialize();
    final maxZoomValue = await controller.getMaxZoomLevel();
    await controller.lockCaptureOrientation();
    if (!mounted) {
      return;
    }

    await controller.startImageStream((CameraImage img) async {
      print("STREAM");
    });

    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return CameraPreview(controller);
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
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'

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.29.2, on macOS 15.5 24F74 darwin-arm64, locale en-CO) [464ms]
    • Flutter version 3.29.2 on channel stable at /Volumes/Data/Sdks/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c236373904 (3 months ago), 2025-03-13 16:17:06 -0400
    • Engine revision 18b71d647a
    • Dart version 3.7.2
    • DevTools version 2.42.3

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [2.3s]
    • Android SDK at /Volumes/Data/Sdks/Android/sdk
    • Platform android-35, build-tools 35.0.1
    • 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.6+-13368085-b895.109)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.3) [972ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16E140
    • 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.3) [10ms]
    • 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.6+-13368085-b895.109)

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

[✓] Connected device (5 available) [6.1s]
    • sdk gphone64 arm64 (mobile)           • emulator-5554             • android-arm64  • Android 16 (API 36) (emulator)
    • Alex’s iPhone (2) (wireless) (mobile) • 00008110-000159A01E81801E • ios            • iOS 18.4.1 22E252
    • macOS (desktop)                       • macos                     • darwin-arm64   • macOS 15.5 24F74 darwin-arm64
    • Mac Designed for iPad (desktop)       • mac-designed-for-ipad     • darwin         • macOS 15.5 24F74 darwin-arm64
    • Chrome (web)                          • chrome                    • web-javascript • Google Chrome 137.0.7151.69

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

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: duplicateIssue is closed as a duplicate of an existing issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions