fix: Correctly propagate Errors in configureSession()

This commit is contained in:
Marc Rousavy 2021-06-29 10:16:38 +02:00
parent f80e606c6d
commit f07f4a8770

View File

@ -202,7 +202,11 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
if (before != enable) { if (before != enable) {
// reconfigure session if frame processor was added/removed to adjust use-cases. // reconfigure session if frame processor was added/removed to adjust use-cases.
GlobalScope.launch(Dispatchers.Main) { GlobalScope.launch(Dispatchers.Main) {
configureSession() try {
configureSession()
} catch (e: CameraError) {
invokeOnError(e)
}
} }
} }
} }
@ -428,7 +432,7 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
Log.i(TAG_PERF, "Session configured in $duration ms! Camera: ${camera!!}") Log.i(TAG_PERF, "Session configured in $duration ms! Camera: ${camera!!}")
invokeOnInitialized() invokeOnInitialized()
} catch (exc: Throwable) { } catch (exc: Throwable) {
val error = when (exc) { throw when (exc) {
is CameraError -> exc is CameraError -> exc
is IllegalArgumentException -> { is IllegalArgumentException -> {
if (exc.message?.contains("too many use cases") == true) { if (exc.message?.contains("too many use cases") == true) {
@ -439,7 +443,6 @@ class CameraView(context: Context) : FrameLayout(context), LifecycleOwner {
} }
else -> UnknownCameraError(exc) else -> UnknownCameraError(exc)
} }
invokeOnError(error)
} }
} }