This repository has been archived by the owner on May 1, 2024. It is now read-only.
Snapshot grid structure info instead of modifying it in place #12646
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
Issue #6247, issue #10470, and https://forums.xamarin.com/discussion/88367/nullreferenceexception-on-grid-calculateautocells-only-xf-ios describe NullReferenceExceptions accessing the
_rows
and_columns
members during Grid layouts. These members are lists of RowDefinition and ColumnDefinition information used during the measurement and layout of the Grid. The information in these lists is not for caching purposes; lists are reset during every measurement and layout operation, and also when computing constraints for the Grid.Because the lists are nullable, certain layout and update conditions (which are very difficult to consistently reproduce) can result in the lists being null while a measurement operation is taking place, crashing the application.
In https://github.com/xamarin/Duplo/pull/3675, a similar issue during LayoutChildren was addressed by snapshotting the lists before handling layout, in case InvalidateMeasure was called during the layout process. These changes formalize that snapshotting by creating a separate class to handle creating the snapshot and using it in LayoutChildren, OnSizeRequest, and ComputeConstraintForView. The nullable lists of row/column definitions have been removed entirely, so a NullReferenceException is no longer an issue.
Issues Resolved
API Changes
None
Platforms Affected
Behavioral/Visual Changes
None
Before/After Screenshots
Not applicable
Testing Procedure
No new tests
PR Checklist