Fix KERN_INVALID_ADDRESS in configureNextLayoutAnimation

Summary:
Changelog: [Internal]

The crash is caused by dereferencing invalid pointer.
This can happen because `UIManager` can outlive `RCTScheduler` and `Scheduler`.

Here we make sure when `Scheduler` is being deconstructed, UIManager's pointer is invalidated.

I don't think this is ideal solution but it should fix the crash.
Ideally we want the owner of animation delegate to invalidate the pointer.

Reviewed By: JoshuaGross

Differential Revision: D21922910

fbshipit-source-id: b2a56c1104574cecebaffad1bcbcbff82c1fa0cf
This commit is contained in:
Samuel Susla 2020-06-07 13:15:31 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 001eb7cbd6
Коммит 6860cb0775
3 изменённых файлов: 4 добавлений и 4 удалений

Просмотреть файл

@ -127,6 +127,7 @@ Scheduler::~Scheduler() {
// The thread-safety of this operation is guaranteed by this requirement.
uiManager_->setDelegate(nullptr);
uiManager_->setAnimationDelegate(nullptr);
// Then, let's verify that the requirement was satisfied.
auto surfaceIds = std::vector<SurfaceId>{};

Просмотреть файл

@ -318,8 +318,7 @@ void UIManager::shadowTreeDidFinishTransaction(
#pragma mark - UIManagerAnimationDelegate
void UIManager::setAnimationDelegate(
UIManagerAnimationDelegate *delegate) const {
void UIManager::setAnimationDelegate(UIManagerAnimationDelegate *delegate) {
animationDelegate_ = delegate;
}

Просмотреть файл

@ -46,7 +46,7 @@ class UIManager final : public ShadowTreeDelegate {
* The delegate is stored as a raw pointer, so the owner must null
* the pointer before being destroyed.
*/
void setAnimationDelegate(UIManagerAnimationDelegate *delegate) const;
void setAnimationDelegate(UIManagerAnimationDelegate *delegate);
void animationTick();
@ -140,7 +140,7 @@ class UIManager final : public ShadowTreeDelegate {
SharedComponentDescriptorRegistry componentDescriptorRegistry_;
UIManagerDelegate *delegate_;
mutable UIManagerAnimationDelegate *animationDelegate_{nullptr};
UIManagerAnimationDelegate *animationDelegate_{nullptr};
UIManagerBinding *uiManagerBinding_;
ShadowTreeRegistry shadowTreeRegistry_{};
};