Skip to content

[BUG] Subsequent image captures result in crash when trying to access captured image #99

@frozenbubble

Description

@frozenbubble

Prerequisites

  • [/] I checked the documentation and found no answer
  • [/] I checked to make sure that this issue has not already been filed

Expected Behavior

When taking multiple subsequent images, onImageCaptured gets called and i can access the captured image without any issues.

Current Behavior

With the following code:

struct CameraSandbox: View {
    @State var captureImage: UIImage?
    @State var displayImage: Bool = false
    
    var body: some View {
        ZStack {
            MCamera()
                .setAudioAvailability(false)
                .setErrorScreen(CustomErrorScreen.init)
                .setCapturedMediaScreen(nil) // Disable captured media screen
                .setCameraScreen(CustomCameraScreen.init)
                .onImageCaptured { (image, controller) in
                    captureImage = image
                    controller.reopenCameraScreen()
                }
                .startSession() // Start the camera session
        }
        .onChange(of: captureImage) {
            displayImage = captureImage != nil
        }
        .sheet(isPresented: $displayImage) {
            if let captureImage {
                Image(uiImage: captureImage)
                    .resizable()
                    .scaledToFit()
            }
        }
    }
}

The first attempt results in the image correctly displayed in the sheet, and the second attempt consistently results in a crash at MijickCamera/CameraManager+PhotoOutput.swift:45:

settings.flashMode = parent.attributes.flashMode.toDeviceFlashMode()

With parent being nil

If i comment out captureImage = image in my onImageCaptured handler, camera sound and animation plays without crash.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Create a camera screen with the captured media screen disabled and custom camera screen
  2. Specify onImageCaptured and try to store the result image
  3. Take subsequent images from the camera screen
  4. Observe crash

Code Sample

See above

Screenshots

N/A

Context

Name Version
SDK e.g. 3.0.2
Xcode Version 16.2 (16C5032a)
Operating System e.g. iOS 18.3.2
Device e.g. iPhone XS

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions