Skip to content

Conversation

@chunhtai
Copy link
Contributor

@chunhtai chunhtai commented Apr 9, 2019

…er of layout cycles

Description

this is caused by double precision error. If we have certain height of widget in sliver list, the way we calculate layout offset of children will introduce some double precision error. Later when we scroll all the way to top, we will try to correct the error by shifting the scroll offset even if it is so tiny and does not really need to be corrected (~2e-14).

Most of the time it is correctable, but some times it fail to do so due to precision error in double operation

for example iphone 6s
corrected_scrollofset = scrolloffset + correction
if scrolloffset = 258.8489087697789 and correction = 0.00000000000002842170943040401
Then the scrolloffset does not change after correction due to precision error.
258.8489087697789 + 0.00000000000002842170943040401 = 258.8489087697789
Thus, it stuck on an infinite update loop.

Related Issues

#23527

Tests

I added the following tests:

https://github.com/chunhtai/flutter/blob/465ade89e57a6d8fffc34094d327bcbb99ee8f7c/packages/flutter/test/rendering/slivers_block_test.dart#L298

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • No, this is not a breaking change.

@chunhtai chunhtai requested review from Hixie and goderbauer April 9, 2019 20:16
@goderbauer goderbauer added the framework flutter/packages/flutter repository. See also f: labels. label Apr 9, 2019
@chunhtai chunhtai force-pushed the issue/23527 branch 3 times, most recently from 9a0bfde to 0c2cc45 Compare April 10, 2019 17:13
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe even better: precisionErrorTolerance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@chunhtai chunhtai merged commit fbeb5e0 into flutter:master Apr 11, 2019
jiisd added a commit to jiisd/flutter that referenced this pull request Apr 12, 2019
* master: (209 commits)
  Allow mouse hover to only respond to some mouse events but not all. (flutter#30886)
  Fix issue 23527: Exception: RenderViewport exceeded its maximum number of layout cycles (flutter#30809)
  Keep hover annotation layers in sync with the mouse detector. (flutter#30829)
  Use identical instead of '==' in a constant expression. (flutter#30921)
  Add toggle for debugProfileWidgetBuilds (flutter#30867)
  Revert "Manual engine roll with disabled service authentication codes (flutter#30919)" (flutter#30930)
  Manual engine roll with disabled service authentication codes (flutter#30919)
  Baseline Aligned Row (flutter#30746)
  [Material] Fix showDialog crasher caused by old contexts (flutter#30754)
  Let `sliver.dart` `_createErrorWidget` work with other Widgets (flutter#30880)
  Add more dialog doc cross-reference (flutter#30887)
  Allow downloading of desktop embedding artifacts (flutter#30648)
  CupertinoDatePicker initialDateTime accounts for minuteInterval  (flutter#30862)
  add golden tests for CupertinoDatePicker (flutter#30828)
  Simplify toImage future handling (flutter#30876)
  Fixed Table flex column layout error flutter#30437 (flutter#30470)
  Fix iTunes Transporter quirk (flutter#30883)
  Bump Android build tools to 28.0.3 in Dockerfile (flutter#30832)
  Update the upload key which seems to have trouble for some reason (flutter#30871)
  Check for invalid elevations (flutter#30215)
  ...

static const double _epsilon = 1e-10;
/// The epsilon of tolerable double precision error.
static const double precisionErrorTolerance = 1e-10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we really shouldn't expose this in our public API. This kind of thing is a hack at best.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy to revert this is this is not preferable. This issue has been happened in a lot different place. There is another bug in performlayout I am trying to fix . https://github.com/flutter/flutter/pull/30979/files
I think it is better to have a central place to define this constant. That is why I exposed this to public api.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's better to expose it and use it consistently than to have it in many places...

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants