Make sure aspect ratio makes sense before setting it. Don't set NaN for aspect ratio, that tends to break things

This commit is contained in:
Tamius Han 2020-03-01 16:55:52 +01:00
parent 4b177a9724
commit c5f6868a63
2 changed files with 18 additions and 1 deletions

View File

@ -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) {

View File

@ -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);
}