Add more asserts to check matrix validity#31701
Conversation
These will help identify where the matrix starts to get wrong. Related issue: flutter#31650
|
Looks like some tests are failing? |
Piinks
left a comment
There was a problem hiding this comment.
Does adding asserts constitute a potentially breaking change?
|
@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); |
There was a problem hiding this comment.
This seems like it should be assert(sizes.source.width != 0), and maybe assert(sizes.source.width.isFinite), no?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
(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); |
There was a problem hiding this comment.
Uber nit:
| 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); |
There was a problem hiding this comment.
Uber nit:
| final double scaleY = _divHandleZero(sizes.destination.height, sizes.source.height); | |
| final double scaleX = _divisionHandleZero(sizes.destination.width, sizes.source.width); |
to avoid abbreviations
There was a problem hiding this comment.
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.
Update the test accordingly See flutter#7489 and flutter#7431 for the original purpose of the test.
a4edf0e to
1257521
Compare
| @override | ||
| void paint(PaintingContext context, Offset offset) { | ||
| if (size.isEmpty) | ||
| if (size.isEmpty || child.size.isEmpty) |
There was a problem hiding this comment.
Should we be checking for isFinite as well?
There was a problem hiding this comment.
Oh, I see, we check that in _updatePaintData
|
Was this not worth merging? |
|
That was a mistake of my local script... Reopen and merge now. |
This reverts commit 0dc290c.
)" (flutter#32496)" This reverts commit 549b412.
Description
These will help identify where the matrix starts to get wrong.
Also fixed
RenderFittexBoxto no longer paint with empty child which previously triggered invalid matrix computations (NaN with dividing by 0). See also #7489Related Issues
#31650
#31700
#7431
Tests
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.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?