Skip to content

Commit

Permalink
Attempt to fix crash during app termination
Browse files Browse the repository at this point in the history
Summary:
changelog: Attempt to fix a crash during app termination on iOS in the new renderer

We need to stop all surfaces before it is terminated to prevent app from crashing.

The crash happens on background thread.
The app crashes because it is probably accessing static variable that has been deallocated by the main thread. How can main thread deallocate things when background thread is still running? Because main thread is attached to our app's process, background thread is provided by the system and continues to live.

Reviewed By: ShikaSD

Differential Revision: D33977161

fbshipit-source-id: 87546d7b70d1aa465e63f0d37b70bae1fffa2304
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Feb 3, 2022
1 parent 70062c1 commit 9cd4334
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions React/Fabric/RCTSurfacePresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ - (instancetype)initWithContextContainer:(ContextContainer::Shared)contextContai
_observers = [NSMutableArray array];

_scheduler = [self _createScheduler];

auto reactNativeConfig = _contextContainer->at<std::shared_ptr<ReactNativeConfig const>>("ReactNativeConfig");
if (reactNativeConfig->getBool("react_native_new_architecture:suspend_before_app_termination")) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_applicationWillTerminate)
name:UIApplicationWillTerminateNotification
object:nil];
}
}

return self;
Expand Down Expand Up @@ -327,6 +335,11 @@ - (void)_stopAllSurfacesWithScheduler:(RCTScheduler *)scheduler
}];
}

- (void)_applicationWillTerminate
{
[self suspend];
}

#pragma mark - RCTSchedulerDelegate

- (void)schedulerDidFinishTransaction:(MountingCoordinator::Shared const &)mountingCoordinator
Expand Down

0 comments on commit 9cd4334

Please sign in to comment.