Skip to content

Comments

Fix crash in NSLayoutManager during autorelease dealloc#523

Merged
tom-un merged 52 commits intomicrosoft:masterfrom
tom-un:tomun/layout-manager-dealloc
Jul 28, 2020
Merged

Fix crash in NSLayoutManager during autorelease dealloc#523
tom-un merged 52 commits intomicrosoft:masterfrom
tom-un:tomun/layout-manager-dealloc

Conversation

@tom-un
Copy link
Collaborator

@tom-un tom-un commented Jul 28, 2020

Please select one of the following

  • I am removing an existing difference between facebook/react-native and microsoft/react-native-macos 👍
  • I am cherry-picking a change from Facebook's react-native into microsoft/react-native-macos 👍
  • I am making a fix / change for the macOS implementation of react-native
  • I am making a change required for Microsoft usage of react-native

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 dealloc calls its own _NSRemoveDirtyLayoutManager method 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 _textStorage ivar 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. #357

Changelog

[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

tom-un and others added 30 commits April 3, 2020 20:53
@tom-un tom-un requested a review from HeyImChris July 28, 2020 18:12
@pull-bot
Copy link

pull-bot commented Jul 28, 2020

Messages
📖

📋 Verify Changelog Format - A changelog entry has the following format: [CATEGORY] [TYPE] - Message.

DetailsCATEGORY may be:
  • General
  • macOS
  • iOS
  • Android
  • JavaScript
  • Internal (for changes that do not need to be called out in the release notes)

TYPE may be:

  • Added, for new features.
  • Changed, for changes in existing functionality.
  • Deprecated, for soon-to-be removed features.
  • Removed, for now removed features.
  • Fixed, for any bug fixes.
  • Security, in case of vulnerabilities.

MESSAGE may answer "what and why" on a feature level. Use this to briefly tell React Native users about notable changes.

Generated by 🚫 dangerJS against 55bd800

// 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];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a good call to copy it. In practice there's only ever a single object in the array but that could change.

Copy link

@HeyImChris HeyImChris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we're hitting the brew bundle CI validation failure here too

@tom-un tom-un merged commit 40c5a66 into microsoft:master Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<TextView>: Intermittent crash in [NSTextStorage dealloc] during AutoRelease

5 participants