Skip to content

Add more asserts to check matrix validity#31701

Merged
liyuqian merged 4 commits intoflutter:masterfrom
liyuqian:check_transform_matrix
May 10, 2019
Merged

Add more asserts to check matrix validity#31701
liyuqian merged 4 commits intoflutter:masterfrom
liyuqian:check_transform_matrix

Conversation

@liyuqian
Copy link
Contributor

@liyuqian liyuqian commented Apr 26, 2019

Description

These will help identify where the matrix starts to get wrong.

Also fixed RenderFittexBox to no longer paint with empty child which previously triggered invalid matrix computations (NaN with dividing by 0). See also #7489

Related Issues

#31650
#31700
#7431

Tests

  • RenderFittedBox does not paint with empty sizes

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?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

These will help identify where the matrix starts to get wrong.

Related issue: flutter#31650
@liyuqian liyuqian requested a review from tvolkert April 26, 2019 23:29
@goderbauer goderbauer added the framework flutter/packages/flutter repository. See also f: labels. label Apr 29, 2019
@goderbauer
Copy link
Member

Looks like some tests are failing?

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Does adding asserts constitute a potentially breaking change?

@liyuqian
Copy link
Contributor Author

@goderbauer yes, we had a diving by zero issue which is fixed in the newest patch.

@Piinks : assert won't break their release/profile build, and it will help them debugging the debug build. So I guess that it's not a breaking change?

final FittedSizes sizes = applyBoxFit(_fit, childSize, size);
final double scaleX = sizes.destination.width / sizes.source.width;
final double scaleY = sizes.destination.height / sizes.source.height;
final double scaleX = _div_handle_zero(sizes.destination.width, sizes.source.width);
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like it should be assert(sizes.source.width != 0), and maybe assert(sizes.source.width.isFinite), no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a possible solution too. We'd have to modify test/rendering/proxy_box_test.dart: RenderFittedBox paint to not send a 0 source width though. Let me see how that test can be modified.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it because it's sending in Size.zero for constraints?

Why did this test pass before but fail now? Your change doesn't seem to have anything to do with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

(It does look like the intention here is to have a size.zero be a no-op though)

final FittedSizes sizes = applyBoxFit(_fit, childSize, size);
final double scaleX = sizes.destination.width / sizes.source.width;
final double scaleY = sizes.destination.height / sizes.source.height;
final double scaleX = _divHandleZero(sizes.destination.width, sizes.source.width);
Copy link
Contributor

Choose a reason for hiding this comment

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

Uber nit:

Suggested change
final double scaleX = _divHandleZero(sizes.destination.width, sizes.source.width);
final double scaleX = _divisionHandleZero(sizes.destination.width, sizes.source.width);

to avoid abbreviations

final double scaleX = sizes.destination.width / sizes.source.width;
final double scaleY = sizes.destination.height / sizes.source.height;
final double scaleX = _divHandleZero(sizes.destination.width, sizes.source.width);
final double scaleY = _divHandleZero(sizes.destination.height, sizes.source.height);
Copy link
Contributor

Choose a reason for hiding this comment

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

Uber nit:

Suggested change
final double scaleY = _divHandleZero(sizes.destination.height, sizes.source.height);
final double scaleX = _divisionHandleZero(sizes.destination.width, sizes.source.width);

to avoid abbreviations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @dnfield and @Piinks for your comments! I've now dropped the _devHandleZero. Instead, I fixed the test and make RenderFittedBox to no longer paint with empty sizes. Add @jason-simmons for review as he wrote the test originally to fix a similar issue with NaN and empty size.

@liyuqian liyuqian requested a review from jason-simmons May 3, 2019 22:17
Update the test accordingly

See flutter#7489 and flutter#7431 for the original purpose of the test.
@liyuqian liyuqian force-pushed the check_transform_matrix branch from a4edf0e to 1257521 Compare May 3, 2019 22:22
@override
void paint(PaintingContext context, Offset offset) {
if (size.isEmpty)
if (size.isEmpty || child.size.isEmpty)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be checking for isFinite as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see, we check that in _updatePaintData

@liyuqian liyuqian closed this May 8, 2019
@liyuqian liyuqian deleted the check_transform_matrix branch May 8, 2019 21:20
@tvolkert
Copy link
Contributor

tvolkert commented May 9, 2019

Was this not worth merging?

@liyuqian liyuqian restored the check_transform_matrix branch May 9, 2019 17:29
@liyuqian liyuqian reopened this May 9, 2019
@liyuqian
Copy link
Contributor Author

liyuqian commented May 9, 2019

That was a mistake of my local script... Reopen and merge now.

liyuqian added a commit to liyuqian/flutter that referenced this pull request May 10, 2019
liyuqian added a commit that referenced this pull request May 13, 2019
This relands #31701 with missing const added

This reverts commit 549b412.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 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.

7 participants