Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit a4dd4aa

Browse files
author
Yuncong Zhang
authored
Merge pull request #401 from UnityTech/fix_table_deadloop
(hotfix) Fix table deadloop
2 parents d8b1506 + 0158191 commit a4dd4aa

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Runtime/rendering/table.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -841,12 +841,17 @@ List<float> _computeColumnWidths(BoxConstraints constraints) {
841841
float deficit = tableWidth - maxWidthConstraint;
842842

843843
int availableColumns = this.columns;
844-
float minimumDeficit = 0.00000001f;
845-
while (deficit > 0.0f && totalFlex > minimumDeficit) {
844+
845+
//(Xingwei Zhu) this deficit is double and set to be 0.00000001f in flutter.
846+
//since we use float by default, making it larger should make sense in most cases
847+
float minimumDeficit = 0.0001f;
848+
while (deficit > minimumDeficit && totalFlex > minimumDeficit) {
846849
float newTotalFlex = 0.0f;
847850
for (int x = 0; x < this.columns; x++) {
848851
if (flexes[x] != null) {
849-
float newWidth = widths[x] - deficit * flexes[x].Value / totalFlex;
852+
//(Xingwei Zhu) in case deficit * flexes[x].Value / totalFlex => 0 if deficit is really small, leading to dead loop,
853+
//we amend it with a default larger value to ensure that this loop will eventually end
854+
float newWidth = widths[x] - Mathf.Max(minimumDeficit, deficit * flexes[x].Value / totalFlex);
850855
D.assert(newWidth.isFinite());
851856
if (newWidth <= minWidths[x]) {
852857
deficit -= widths[x] - minWidths[x];

0 commit comments

Comments
 (0)