Fix crash in NSLayoutManager during autorelease dealloc#523
Merged
tom-un merged 52 commits intomicrosoft:masterfrom Jul 28, 2020
Merged
Fix crash in NSLayoutManager during autorelease dealloc#523tom-un merged 52 commits intomicrosoft:masterfrom
tom-un merged 52 commits intomicrosoft:masterfrom
Conversation
…iew." This reverts commit 5a67ae0.
|
Libraries/Text/Text/RCTTextView.m
Outdated
| // associated NSLayoutManager dealloc later in an autorelease pool. | ||
| // Manually removing the layout managers from _textStorage prior to release | ||
| // works around this issue in AppKit. | ||
| NSArray<NSLayoutManager *> *managers = [_textStorage layoutManagers]; |
There was a problem hiding this comment.
Can we confirm this makes a copy so we don't crash on mutating a collection while iterating it? If not we should explicitly copy the result of [_textStorage layoutManagers]
Collaborator
Author
There was a problem hiding this comment.
Its a good call to copy it. In practice there's only ever a single object in the array but that could change.
HeyImChris
approved these changes
Jul 28, 2020
HeyImChris
left a comment
There was a problem hiding this comment.
Looks like we're hitting the brew bundle CI validation failure here too
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Please select one of the following
Summary
The RCTTextView has an NSTextStorage ivar. When these objects are released and dealloced in an autorelease pool, sometimes there can be an exception thrown in system code as
NSLayoutManager dealloccalls its own_NSRemoveDirtyLayoutManagermethod which fails on a call to-[NSConcretePointerArray removePointerAtIndex:].We used to hit this issue consistently when resizing a window that contained many runs of text. The workaround was to manually remove all layout managers from the
_textStorageivar just prior to replacing it with another NSTextStorage.Even with this fix, the
[RNTesterSnapshotTests testTextExample]test would still occasionally crash with the same callstack, and now @ospfranco reported the crash in a dependent project. Doing the same operation of manually removing all the layout managers from the text storage in RCTTextView dealloc seems to fix the issue. #357Changelog
[fixed] [macOS] - Fix crash in NSLayoutManager during autorelease dealloc
Test Plan
Re-enabled the previously disabled
[RNTesterSnapshotTests testTextExample]test. @ospfranco manually tested the change.Microsoft Reviewers: Open in CodeFlow