Skip to content

Commit f20bec8

Browse files
lyahdavchristophpurrer
authored andcommitted
Fix crash in RCTTextView related to NSLayoutManager
Summary: In a prior diff we removed some code that fixed an occasional crash in RCTTextView. This diff brings back the code, adapted from microsoft#523. Test Plan: Open the Text section of RNTester several times and verify no crash: |Before|After| |{F612971452}|{F612971479}| Reviewers: skyle Reviewed By: skyle Subscribers: eliwhite Differential Revision: https://phabricator.intern.facebook.com/D28166631 Tasks: T78743077 Signature: 28166631:1620086528:d359ab6e0c3477f2e52784534b6763156b33b1e5
1 parent bb7ea1d commit f20bec8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Libraries/Text/Text/RCTTextView.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,17 @@ - (void)setTextStorage:(NSTextStorage *)textStorage
231231

232232
[_textView replaceTextContainer:textContainer];
233233

234+
// On macOS AppKit can throw an uncaught exception
235+
// (-[NSConcretePointerArray pointerAtIndex:]: attempt to access pointer at index ...)
236+
// during the dealloc of NSLayoutManager. The textStorage and its
237+
// associated NSLayoutManager dealloc later in an autorelease pool.
238+
// Manually removing the layout managers from textStorage prior to release
239+
// works around this issue in AppKit.
240+
NSArray<NSLayoutManager *> *managers = [[textStorage layoutManagers] copy];
241+
for (NSLayoutManager *manager in managers) {
242+
[textStorage removeLayoutManager:manager];
243+
}
244+
234245
_textView.minSize = contentFrame.size;
235246
_textView.maxSize = contentFrame.size;
236247
_textView.frame = contentFrame;

0 commit comments

Comments
 (0)