Skip to content

[camera] changing camera while recording causes a crash due to disconnected AVOutput #194344

Closed
flutter/packages
#13248

Description

@hellohuanlin

Steps to reproduce

2 ways to repro:

  1. Follow these steps to run camera_avfoundation's integration test: [iOS 27] camera_avfoundation integration tests fail for image/video resolution and image output format #191202
  2. simply start video recording and then set description:
await controller.startVideoRecording();
await controller.setDescription(cameras[1]);

Expected results

Test should pass

Actual results

Crashes with PathNotFoundException: Deletion failed ... core_devices

Code sample

NA

Screenshots or Video

NA

Logs

NA

Flutter Doctor output

NA

Activity

  1. self-assigned this
    on Oct 14, 2026
  2. hellohuanlin commented on Oct 14, 2026

    @hellohuanlin
    ContributorAuthor

    This is a bug in https://github.com/flutter/packages/blob/ac2db9cfeaf69c5064739e0d477ef8cb9c19cd35/packages/camera/camera_avfoundation/darwin/camera_avfoundation/Sources/camera_avfoundation/DefaultCamera.swift#L1258

    Before switching camera, the capture session has:

    Inputs:       [ backCameraInput ]
    Outputs:      [ captureVideoOutput, capturePhotoOutput ]
    Connections:
      Wire 1: backCameraInput  -> captureVideoOutput   (created manually via addConnection)
      Wire 2: backCameraInput  -> capturePhotoOutput   (created automatically via addOutput)
    

    When switching camera input, we remove video input and output, but left photo output untouched. So at this point the capture session has:

    Inputs:       [ ]
    Outputs:      [ capturePhotoOutput ]   <-- still in the session, but unplugged!
    Connections:  [ ]                      <-- both Wire 1 and Wire 2 were deleted!
    

    Now when adding back the camera input, we simply do:

    videoCaptureSession.addInputWithNoConnections(captureVideoInput)
    videoCaptureSession.addOutputWithNoConnections(captureVideoOutput.avOutput)
    

    So our capture session ends up with:

    Inputs:       [ frontCameraInput ]
    Outputs:      [ capturePhotoOutput, newVideoOutput ]
    Connections:
      Wire 1: frontCameraInput -> newVideoOutput
      Wire 2: (MISSING! capturePhotoOutput has no wire to frontCameraInput!)
    

    Then a subsequent code calls

    capturePhotoOutput.maxPhotoDimensions = maxSupportedDimensions
    

    Which throws NSInvalidArgumentException because it has no connection.

    The fix is simply change the code to videoCaptureSession.addInput(captureVideoInput), which would automatically add the frontCameraInput -> capturePhotoOutput connection.

  3. added
    P1High-priority issues at the top of the work list
    triaged-iosTriaged by iOS platform team
    on Oct 14, 2026
  4. github-actions commented on Oct 30, 2026

    @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.

  5. locked as resolved and limited conversation to collaborators on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listfyi-ecosystemFor the attention of Ecosystem teamp: cameraThe camera pluginplatform-iosiOS applications specificallyteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions