Skip to content

Commit 9cd4334

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Attempt to fix crash during app termination
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
1 parent 70062c1 commit 9cd4334

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

React/Fabric/RCTSurfacePresenter.mm

+13
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ - (instancetype)initWithContextContainer:(ContextContainer::Shared)contextContai
9999
_observers = [NSMutableArray array];
100100

101101
_scheduler = [self _createScheduler];
102+
103+
auto reactNativeConfig = _contextContainer->at<std::shared_ptr<ReactNativeConfig const>>("ReactNativeConfig");
104+
if (reactNativeConfig->getBool("react_native_new_architecture:suspend_before_app_termination")) {
105+
[[NSNotificationCenter defaultCenter] addObserver:self
106+
selector:@selector(_applicationWillTerminate)
107+
name:UIApplicationWillTerminateNotification
108+
object:nil];
109+
}
102110
}
103111

104112
return self;
@@ -327,6 +335,11 @@ - (void)_stopAllSurfacesWithScheduler:(RCTScheduler *)scheduler
327335
}];
328336
}
329337

338+
- (void)_applicationWillTerminate
339+
{
340+
[self suspend];
341+
}
342+
330343
#pragma mark - RCTSchedulerDelegate
331344

332345
- (void)schedulerDidFinishTransaction:(MountingCoordinator::Shared const &)mountingCoordinator

0 commit comments

Comments
 (0)