From c5f6868a637b7a9fd69f160cad92f1878e3089a3 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sun, 1 Mar 2020 16:55:52 +0100 Subject: [PATCH] Make sure aspect ratio makes sense before setting it. Don't set NaN for aspect ratio, that tends to break things --- src/ext/lib/ar-detect/ArDetector.js | 6 +++++- src/ext/lib/video-transform/Resizer.js | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ext/lib/ar-detect/ArDetector.js b/src/ext/lib/ar-detect/ArDetector.js index 1f95469..6bd4e36 100644 --- a/src/ext/lib/ar-detect/ArDetector.js +++ b/src/ext/lib/ar-detect/ArDetector.js @@ -391,7 +391,11 @@ class ArDetector { //#endregion getDefaultAr() { - return this.video.videoWidth / this.video.videoHeight; + const ratio = this.video.videoWidth / this.video.videoHeight; + if (isNaN(ratio)) { + return undefined; + } + return ratio; } calculateArFromEdges(edges) { diff --git a/src/ext/lib/video-transform/Resizer.js b/src/ext/lib/video-transform/Resizer.js index f268ddb..849d4cb 100644 --- a/src/ext/lib/video-transform/Resizer.js +++ b/src/ext/lib/video-transform/Resizer.js @@ -121,6 +121,19 @@ class Resizer { updateAr(ar) { + if (!ar) { + return; + } + + // Some options require a bit more testing re: whether they make sense + // if they don't, we refuse to update aspect ratio until they do + if (ar.type === AspectRatio.Automatic || ar.type === AspectRatio.Fixed) { + if (!ar.ratio || isNaN(ar.ratio)) { + return; + } + } + + // Only update aspect ratio if there's a difference between the old and the new state if (!this.lastAr || ar.type !== this.lastAr.type || ar.ratio !== this.lastAr.ratio) { this.setAr(ar); }