浏览代码

fix potential dead loop

/main
xingwei.zhu 5 年前
当前提交
7c88e99b
共有 1 个文件被更改,包括 8 次插入3 次删除
  1. 11
      Runtime/rendering/table.cs

11
Runtime/rendering/table.cs


float deficit = tableWidth - maxWidthConstraint;
int availableColumns = this.columns;
float minimumDeficit = 0.00000001f;
while (deficit > 0.0f && totalFlex > minimumDeficit) {
//(Xingwei Zhu) this deficit is double and set to be 0.00000001f in flutter.
//since we use float by default, making it larger should make sense in most cases
float minimumDeficit = 0.0001f;
while (deficit > minimumDeficit && totalFlex > minimumDeficit) {
float newWidth = widths[x] - deficit * flexes[x].Value / totalFlex;
//(Xingwei Zhu) in case deficit * flexes[x].Value / totalFlex => 0 if deficit is really small, leading to dead loop,
//we amend it with a default larger value to ensure that this loop will eventually end
float newWidth = widths[x] - Mathf.Max(minimumDeficit, deficit * flexes[x].Value / totalFlex);
D.assert(newWidth.isFinite());
if (newWidth <= minWidths[x]) {
deficit -= widths[x] - minWidths[x];

正在加载...
取消
保存