Skip to content

Commit bc6e350

Browse files
committed
Sanity check view, ROI and frame metrics
Because `roundToInt` in `Rect.setFrameRoi()` throws an `IllegalArgumentException: Cannot round NaN value` for some people out there.
1 parent c9c1b2f commit bc6e350

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

app/src/main/kotlin/de/markusfisch/android/binaryeye/activity/CameraActivity.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,16 @@ class CameraActivity : AppCompatActivity() {
647647

648648
private fun updateFrameRoiAndMappingMatrix() {
649649
val viewRect = cameraView.previewRect
650-
val viewRoi = if (detectorView.roi.width() < 1) {
650+
if (viewRect.width() < 1 ||
651+
viewRect.height() < 1 ||
652+
!frameMetrics.isValid()
653+
) {
654+
return
655+
}
656+
val viewRoi = if (
657+
detectorView.roi.width() < 1 ||
658+
detectorView.roi.height() < 1
659+
) {
651660
viewRect
652661
} else {
653662
detectorView.roi

app/src/main/kotlin/de/markusfisch/android/binaryeye/graphics/Mapping.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ data class FrameMetrics(
1010
var width: Int = 0,
1111
var height: Int = 0,
1212
var orientation: Int = 0
13-
)
13+
) {
14+
fun isValid() = width > 0 && height > 0
15+
}
1416

1517
fun Rect.setFrameRoi(
1618
frameMetrics: FrameMetrics,

0 commit comments

Comments
 (0)