Skip to content

Commit 5b1e5f3

Browse files
committed
fix: Skip if no Preview Output is attached
1 parent f91adb1 commit 5b1e5f3

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

package/android/src/main/java/com/mrousavy/camera/core/CameraSession.kt

+12-3
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
347347
codeScannerOutput = output
348348
}
349349

350+
if (outputs.isEmpty()) {
351+
Log.w(TAG, "Cannot create Camera Session without any outputs. Aborting...")
352+
return
353+
}
354+
350355
// Create new session
351356
captureSession = cameraDevice.createCaptureSession(cameraManager, outputs, { session ->
352357
if (this.captureSession == session) {
@@ -372,14 +377,18 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
372377
return
373378
}
374379

380+
val previewOutput = previewOutput
381+
if (previewOutput == null) {
382+
Log.w(TAG, "Preview Output is null, aborting...")
383+
return
384+
}
385+
375386
val cameraCharacteristics = cameraManager.getCameraCharacteristics(device.id)
376387

377388
val template = if (config.video.isEnabled) CameraDevice.TEMPLATE_RECORD else CameraDevice.TEMPLATE_PREVIEW
378389
val captureRequest = device.createCaptureRequest(template)
379390

380-
previewOutput?.let { output ->
381-
captureRequest.addTarget(output.surface)
382-
}
391+
captureRequest.addTarget(previewOutput.surface)
383392
videoOutput?.let { output ->
384393
captureRequest.addTarget(output.surface)
385394
}

0 commit comments

Comments
 (0)