getbouncer/cardscan-android

Fatal exception due to wrong coroutine context

Closed this issue · 1 comments

We got a crash in production.
CardScan should switch to the main coroutine context before opening the alert dialog.
Here is the stacktrace.

Fatal Exception: java.lang.RuntimeException: Can't create handler inside thread Thread[DefaultDispatcher-worker-11,5,main] that has not called Looper.prepare()
       at android.os.Handler.<init>(Handler.java:227)
       at android.os.Handler.<init>(Handler.java:129)
       at android.app.Dialog.<init>(Dialog.java:163)
       at android.app.Dialog.<init>(Dialog.java:248)
       at androidx.appcompat.app.AppCompatDialog.<init>(AppCompatDialog.java:57)
       at androidx.appcompat.app.AlertDialog.<init>(AlertDialog.java:98)
       at androidx.appcompat.app.AlertDialog$Builder.create(AlertDialog.java:983)
       at androidx.appcompat.app.AlertDialog$Builder.show(AlertDialog.java:1008)
       at com.getbouncer.scan.ui.CameraErrorListenerImpl.showCameraError(CameraErrorListenerImpl.java:92)
       at com.getbouncer.scan.ui.CameraErrorListenerImpl.onCameraOpenError(CameraErrorListenerImpl.java:75)
       at com.getbouncer.scan.camera.camera1.Camera1Adapter$startCameraPreview$1.a_(Camera1Adapter.java:190)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:106)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.parkedWorkersStackPop(CoroutineScheduler.java:571)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:750)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:678)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:665)

@francescocervone Thank you very much for the report. I've changed our camera code to ensure the error handler is called on the main thread only. This will go out today as part of release 2.0.0083.