Avoid WPMediaPickerViewController
performBatchUpdates
crash by wrapping the call in try-catch block
#412
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.
Fixes wordpress-mobile/WordPress-iOS#21102
Description
WPMediaPickerViewController
crashes withNSInternalInconsistencyException
. The crash is not always reproducible but spiked significantly with 22.8 release.The rise in crashes could be related to some changes in media-picker and a new collection view exception in iOS 16.4.
The proposed (short-term) solution for NSInternalInconsistencyException crashes it to wrap performBatchUpdates in the try catch block.
Apple documentation indicates if the collection view’s layout isn’t up to date before you call performBatchUpdates, additional reload may occur that can cause problems. Developers should update the data model inside the updates block or ensure the layout is updated before calling performBatchUpdates. However, MediaLibraryPickerDataSource reloads the data source before view controller gets informed about updates, creating a possibility for a crash.
: https://developer.apple.com/documentation/uikit/uicollectionview/1618045-performbatchupdates
Apple engineers reiterate this fact and point out the best way to avoid this issue is to adopt
UICollectionViewDiffableDataSource
which requires refactoring of the current solution.Link to Apple forum thread: https://developer.apple.com/forums/thread/728797?answerId=751887022#751887022
To test:
The crash is only reproducible in some of the cases, we couldn't determine an environment that would make the issue reproducible consistently.
Before
RPReplay_Final1690980668.MP4
After
RPReplay_Final1690980157.MP4
CHANGELOG.md
if necessary.