Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ @implementation FlutterViewController {
blink::ViewportMetrics _viewportMetrics;
BOOL _initialized;
BOOL _viewOpaque;
BOOL _engineNeedsLaunch;
BOOL _isEmbedEngine;
}

#pragma mark - Manage and override all designated initializers
Expand All @@ -49,7 +49,7 @@ - (instancetype)initWithEngine:(FlutterEngine*)engine
if (self) {
_viewOpaque = YES;
_engine.reset([engine retain]);
_engineNeedsLaunch = NO;
_isEmbedEngine = FALSE;
_flutterView.reset([[FlutterView alloc] initWithDelegate:_engine opaque:self.isViewOpaque]);
_weakFactory = std::make_unique<fml::WeakPtrFactory<FlutterViewController>>(self);

Expand All @@ -70,9 +70,9 @@ - (instancetype)initWithProject:(FlutterDartProject*)projectOrNil
_engine.reset([[FlutterEngine alloc] initWithName:@"io.flutter"
project:projectOrNil
allowHeadlessExecution:NO]);
_isEmbedEngine = TRUE;
_flutterView.reset([[FlutterView alloc] initWithDelegate:_engine opaque:self.isViewOpaque]);
[_engine.get() createShell:nil libraryURI:nil];
_engineNeedsLaunch = YES;
[self loadDefaultSplashScreenView];
[self performCommonViewControllerInitialization];
}
Expand Down Expand Up @@ -388,10 +388,9 @@ - (void)surfaceUpdated:(BOOL)appeared {

- (void)viewWillAppear:(BOOL)animated {
TRACE_EVENT0("flutter", "viewWillAppear");

if (_engineNeedsLaunch) {
if (_isEmbedEngine) {
[_engine.get() createShell:nil libraryURI:nil];
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure this will lead to unexpected loss of state. If we allow the engine to get torn down here, restarting it will prevent th ecrash but also restart the app from scratch.

[_engine.get() launchEngine:nil libraryURI:nil];
_engineNeedsLaunch = NO;
}
[_engine.get() setViewController:self];

Expand Down Expand Up @@ -501,6 +500,8 @@ - (void)applicationWillEnterForeground:(NSNotification*)notification {
// touch is specified in the second argument.
- (void)dispatchTouches:(NSSet*)touches
pointerDataChangeOverride:(blink::PointerData::Change*)overridden_change {
if (!(self.isViewLoaded && self.view.window))
return;
const CGFloat scale = [UIScreen mainScreen].scale;
auto packet = std::make_unique<blink::PointerDataPacket>(touches.count);

Expand Down