RedApparat / Fotoapparat

Making Camera for Android more friendly. 📸
Apache License 2.0
3.82k stars 405 forks source link

Fatal, uncaught InterruptedException: No surface became available #165

Closed jpribble closed 6 years ago

jpribble commented 6 years ago

I just upgraded to v2.0.0 and found this fatal exception when first starting the camera. It only occurred once and I was unable to reproduce it (tried about 30 times).

How did you initialize FA?

Fotoapparat
        .with(this)
        .into(cameraView!!)
        .previewScaleType(ScaleType.CenterCrop)
        .photoResolution([custom_selector])
        .previewResolution([custom_selector])
        .lensPosition(single(LensPosition.Back))
        .focusMode(firstAvailable(
            continuousFocusPicture(),
            autoFocus(),
            fixed()))
        .flash(off())
        .frameProcessor {
          processFrame(it)
        }
        .previewFpsRange(highestFps())
        .cameraErrorCallback { e ->
          [error_handling_code]
        }
        .logger(logcat())
        .build()

What was the result you received?

Fotoapparat crashed with a fatal exception when trying to start the camera.

Stack Trace:

01-02 14:47:19.127 E/AndroidRuntime(24687): FATAL EXCEPTION: pool-4-thread-1 01-02 14:47:19.127 E/AndroidRuntime(24687): Process: [redacted], PID: 24687 01-02 14:47:19.127 E/AndroidRuntime(24687): java.lang.Error: java.lang.InterruptedException: No surface became available. 01-02 14:47:19.127 E/AndroidRuntime(24687): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1139) 01-02 14:47:19.127 E/AndroidRuntime(24687): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 01-02 14:47:19.127 E/AndroidRuntime(24687): at java.lang.Thread.run(Thread.java:762) 01-02 14:47:19.127 E/AndroidRuntime(24687): Caused by: java.lang.InterruptedException: No surface became available. 01-02 14:47:19.127 E/AndroidRuntime(24687): at io.fotoapparat.view.CameraView.getPreviewAfterLatch(CameraView.kt:66) 01-02 14:47:19.127 E/AndroidRuntime(24687): at io.fotoapparat.view.CameraView.getPreview(CameraView.kt:53) 01-02 14:47:19.127 E/AndroidRuntime(24687): at io.fotoapparat.routine.camera.StartRoutineKt.start(StartRoutine.kt:54) 01-02 14:47:19.127 E/AndroidRuntime(24687): at io.fotoapparat.routine.camera.StartRoutineKt.bootStart(StartRoutine.kt:20) 01-02 14:47:19.127 E/AndroidRuntime(24687): at io.fotoapparat.Fotoapparat$start$1.invoke(Fotoapparat.kt:86) 01-02 14:47:19.127 E/AndroidRuntime(24687): at io.fotoapparat.Fotoapparat$start$1.invoke(Fotoapparat.kt:40) 01-02 14:47:19.127 E/AndroidRuntime(24687): at io.fotoapparat.hardware.ExecutorKt$sam$Runnable$ffbfbfd0.run(Executor.kt) 01-02 14:47:19.127 E/AndroidRuntime(24687): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 01-02 14:47:19.127 E/AndroidRuntime(24687): ... 2 more

What did you expect?

Expected for the camera to start successfully and not crash. If there is an exception while starting, pass the error to the cameraErrorCallback listener.

Context:

Diolor commented 6 years ago

Let's do that. Should be happening only if the CameraView#onDetachedFromWindow got called quicker than the preview surface became available. UnavailableSurfaceException will be returned in cameraErrorCallback for transparency but can be normally get ignored.