mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[ios] fix background crash when FlutterViewController is destroyed after engine destroyed context (flutter/engine#41037)
[ios] fix background crash when FlutterViewController is destroyed after engine destroyed context
This commit is contained in:
parent
b3e7898f48
commit
94fa5f4edf
@ -434,7 +434,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
_undoManagerPlugin.get().viewController = nil;
|
||||
if (!_allowHeadlessExecution) {
|
||||
[self destroyContext];
|
||||
} else {
|
||||
} else if (_shell) {
|
||||
flutter::PlatformViewIOS* platform_view = [self iosPlatformView];
|
||||
if (platform_view) {
|
||||
platform_view->SetOwnerViewController({});
|
||||
|
||||
@ -12,6 +12,8 @@
|
||||
|
||||
@implementation FlutterEngineTest
|
||||
|
||||
extern NSNotificationName const FlutterViewControllerWillDealloc;
|
||||
|
||||
- (void)testIsolateId {
|
||||
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil];
|
||||
XCTAssertNil(engine.isolateId);
|
||||
@ -48,4 +50,40 @@
|
||||
XCTAssertNil(engine.lifecycleChannel);
|
||||
}
|
||||
|
||||
// https://github.com/flutter/flutter/issues/123776
|
||||
- (void)testReleaseViewControllerAfterDestroyContextInHeadlessMode {
|
||||
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
|
||||
project:nil
|
||||
allowHeadlessExecution:YES];
|
||||
XCTAssertNil(engine.navigationChannel);
|
||||
XCTAssertNil(engine.platformChannel);
|
||||
XCTAssertNil(engine.lifecycleChannel);
|
||||
|
||||
XCTAssertTrue([engine run]);
|
||||
|
||||
XCTAssertNotNil(engine.navigationChannel);
|
||||
XCTAssertNotNil(engine.platformChannel);
|
||||
XCTAssertNotNil(engine.lifecycleChannel);
|
||||
XCTestExpectation* expectation =
|
||||
[[XCTestExpectation alloc] initWithDescription:@"notification called"];
|
||||
@autoreleasepool {
|
||||
FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
|
||||
nibName:nil
|
||||
bundle:nil];
|
||||
[engine setViewController:viewController];
|
||||
[engine destroyContext];
|
||||
[[NSNotificationCenter defaultCenter] addObserverForName:FlutterViewControllerWillDealloc
|
||||
object:nil
|
||||
queue:[NSOperationQueue mainQueue]
|
||||
usingBlock:^(NSNotification* _Nonnull note) {
|
||||
[expectation fulfill];
|
||||
}];
|
||||
viewController = nil;
|
||||
}
|
||||
[self waitForExpectations:@[ expectation ] timeout:30.0];
|
||||
XCTAssertNil(engine.navigationChannel);
|
||||
XCTAssertNil(engine.platformChannel);
|
||||
XCTAssertNil(engine.lifecycleChannel);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user