Auto merge of #29863 - nicoburns:fix-infinite-loop-when-shrinking, r=Loirooriol

Fix infinite loop in flexbox algorithm

Only apply step 5c of "resolve flexible lengths" if sum of scaled flexible shrink factors > 0
Probably fixes #29852 (but speculative as I can't get mach to run).

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___
This commit is contained in:
bors-servo 2023-06-10 16:54:24 +02:00 committed by GitHub
commit 7d9839acc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 9 additions and 10 deletions

View file

@ -976,10 +976,12 @@ impl FlexLine<'_> {
let scaled_shrink_factors_sum: Length = unfrozen_items()
.map(|(item, _)| scaled_shrink_factor(item))
.sum();
for (item, target_main_size) in unfrozen_items() {
let ratio = scaled_shrink_factor(item) / scaled_shrink_factors_sum;
target_main_size
.set(item.flex_base_size - remaining_free_space.abs() * ratio);
if scaled_shrink_factors_sum > Length::zero() {
for (item, target_main_size) in unfrozen_items() {
let ratio = scaled_shrink_factor(item) / scaled_shrink_factors_sum;
target_main_size
.set(item.flex_base_size - remaining_free_space.abs() * ratio);
}
}
}
}