android / android/camera-samples
Found bug in logic when making photo very often (tapping take photo button fast and continuously)
Abierto
@ggfan ya está trabajando en esto.
Desde el 2/9/2021.
- Lenguaje dominante
- Kotlin
- Estrellas
- 5.5k
- Forks
- 2.4k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
So there is a bug when coroutine can endlessly wait https://github.com/android/camera-samples/blob/main/Camera2Basic/app/src/main/java/com/example/android/camera2/basic/fragments/CameraFragment.kt#L372
It may happen if you make many photos by tapping take photo button fast and continuously for some time
The solution is to safely quit this while statement before resuming the coroutine with the result:
var image: Image? = null
while (image == null) { // ADD CONDITION TO SAFELY QUIT WHILE!!!
// Dequeue images while timestamps don't match
image = imageQueue.take()
// TODO(owahltinez): b/142011420
// if (image.timestamp != resultTimestamp) continue
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
&& image.timestamp != resultTimestamp
) {
image = null // RESET TO NULL IF NOT CORRECT ONE
continue
}
if (DEBUG) Timber.d("Matching image dequeued: ${image.timestamp}")
// Unset the image reader listener
Timber.d("takePhotoooo Runnable removeCallbacks")
imageReaderHandler.removeCallbacks(timeoutRunnable)
imageReader.setOnImageAvailableListener(null, null)
// Clear the queue of images, if there are left
while (imageQueue.size > 0) {
imageQueue.take().close()
}
val rotation = relativeOrientation.value ?: 0
val mirrored = characteristics.get(CameraCharacteristics.LENS_FACING) ==
CameraCharacteristics.LENS_FACING_FRONT
val exifOrientation = computeExifOrientation(rotation, mirrored)
// Build the result and resume progress
//cont.resume(CombinedCaptureResult(image, result, exifOrientation, imageReader.imageFormat))
// NOT SAFE!!!!!!
// There is no need to break out of the loop, this coroutine will suspend // IT'S NOT RIGHT STILL, BETTER BREAK IT AND CONTINUE COROUTINE AFTER IT!!!
}
cont.resume(CombinedCaptureResult(image, result, exifOrientation, imageReader.imageFormat))
// THIS IS MUCH BETTER
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Evaluación
Este issue todavía no se ha evaluado.