Skip to content

Commit a141892

Browse files
authored
Fix crash with 0 video dimensions (#871)
Resolves #869 I see more places where division by 0 can take place, but this is crucial for layout.
1 parent 4ae92ff commit a141892

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

.changes/video-view-crash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
patch type="fixed" "Crash in VideoView when video dimensions are both 0"

Sources/LiveKit/Track/Capturers/CameraCapturer.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ extension LKRTCVideoFrame {
425425
let sourceRatio = Double(width) / Double(height)
426426
let targetRatio = Double(scaleWidth) / Double(scaleHeight)
427427

428+
guard targetRatio.isFinite else { return nil }
429+
428430
// Calculate crop dimensions
429431
let (cropWidth, cropHeight): (Int32, Int32)
430432
if sourceRatio > targetRatio {

Sources/LiveKit/Views/VideoView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public class VideoView: NativeView, Loggable {
469469
let hRatio = size.height / hDim
470470
let ratioDiff = abs(hRatio - wRatio)
471471

472-
if ratioDiff < CGFloat.aspectRatioTolerance {
472+
if !ratioDiff.isFinite || ratioDiff < CGFloat.aspectRatioTolerance {
473473
// no-op
474474
} else if state.layoutMode == .fill ? hRatio > wRatio : hRatio < wRatio {
475475
size.width = size.height / hDim * wDim

0 commit comments

Comments
 (0)