Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pekaboo crashes on iOS with "startRunning may not be called between calls to beginConfiguration and commitConfiguration" #91

Open
shtolik opened this issue Jun 19, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@shtolik
Copy link
Contributor

shtolik commented Jun 19, 2024

There were crashes on iOS devices when retaking images again and initialCameraMode is passed to rememberPeekabooCameraState.

Not on every image retake, but quite often. I was able to reproduce the problem by adding it into sample code of camera setup in this repo as well.
val state = rememberPeekabooCameraState(initialCameraMode = cameraMode, onCapture = onCapture)
where cameraMode is passed as variable to PeekabooCameraView (i think it wasn't crashing if i just set locally initialCameraMode = CameraMode.Back, but not sure).

That's the crash description

** Terminating app due to uncaught exception 'NSGenericException', reason: '*** -[AVCaptureSession startRunning] startRunning may not be called between calls to beginConfiguration and commitConfiguration'

And then debug breakpoint is activate in the place below.

PeekabooCamera.ios.kt
...

@OptIn(ExperimentalForeignApi::class)
@Composable
private fun RealDeviceCamera(
    state: PeekabooCameraState,
    camera: AVCaptureDevice,
    modifier: Modifier,
) {
....
    UIKitView(
        modifier = modifier,
        background = Color.Black,
        factory = {
            val dispatchGroup = dispatch_group_create()
            val cameraContainer = UIView()
            cameraContainer.layer.addSublayer(cameraPreviewLayer)
            cameraPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
            dispatch_group_enter(dispatchGroup)
            dispatch_async(queue) {
-- crash break point -->                captureSession.startRunning()
                dispatch_group_leave(dispatchGroup)
            }

So I stopped passing that variable in my app and I think it helped, but need to test on more device - so there is a workaround, but would be great to fix it.

@shtolik shtolik changed the title Pekaboo crashes if cameraMode variable passed to rememberPeekabooCameraState Pekaboo crashes on iOS if cameraMode variable passed to rememberPeekabooCameraState Jun 19, 2024
@shtolik
Copy link
Contributor Author

shtolik commented Jun 20, 2024

So it may not be this camerMode related, still crashes without setting it on ios quite often:(

@shtolik shtolik changed the title Pekaboo crashes on iOS if cameraMode variable passed to rememberPeekabooCameraState Pekaboo crashes on iOS with "startRunning may not be called between calls to beginConfiguration and commitConfiguration" Jun 20, 2024
@nickfaces
Copy link

nickfaces commented Aug 16, 2024

@shtolik

In PeekabooCamera.ios.kt try change this

        dispatch_group_enter(dispatchGroup)
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT.toLong(), 0UL)) {
            captureSession.startRunning()
            dispatch_group_leave(dispatchGroup)
        }
        captureSession.commitConfiguration()

        dispatch_group_notify(dispatchGroup, dispatch_get_main_queue()) {
            onCameraReady()
        }

to

        captureSession.commitConfiguration()

        dispatch_async(queue) {
            captureSession.startRunning()

            dispatch_async(dispatch_get_main_queue()) {
                state.onCameraReady()
            }
        }

@onseok onseok added the bug Something isn't working label Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants