Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Unblock FlutterResizeSynchronizer on engine shutdown #24264

Merged
merged 1 commit into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions shell/platform/darwin/macos/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ - (void)shutDownEngine {
return;
}

if (_viewController && _viewController.flutterView) {
[_viewController.flutterView shutdown];
}

FlutterEngineResult result = _embedderAPI.Deinitialize(_engine);
if (result != kSuccess) {
NSLog(@"Could not de-initialize the Flutter engine: error %d", result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,9 @@
*/
- (void)requestCommit;

/**
* Called when shutting down. Unblocks everything and prevents any further synchronization.
*/
- (void)shutdown;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ @interface FlutterResizeSynchronizer () {
// Target size for resizing.
CGSize _newSize;

// if YES prevents all synchronization
BOOL _shuttingDown;

__weak id<FlutterResizeSynchronizerDelegate> _delegate;
}
@end
Expand All @@ -54,7 +57,7 @@ - (void)beginResize:(CGSize)size notify:(dispatch_block_t)notify {
return;
}

if (!_receivedFirstFrame) {
if (!_receivedFirstFrame || _shuttingDown) {
// No blocking until framework produces at least one frame
notify();
return;
Expand All @@ -77,7 +80,7 @@ - (void)beginResize:(CGSize)size notify:(dispatch_block_t)notify {

_waiting = YES;

_condBlockRequestCommit.wait(lock, [&] { return _pendingCommit; });
_condBlockRequestCommit.wait(lock, [&] { return _pendingCommit || _shuttingDown; });

[_delegate resizeSynchronizerFlush:self];
[_delegate resizeSynchronizerCommit:self];
Expand All @@ -104,7 +107,7 @@ - (BOOL)shouldEnsureSurfaceForSize:(CGSize)size {

- (void)requestCommit {
std::unique_lock<std::mutex> lock(_mutex);
if (!_acceptingCommit) {
if (!_acceptingCommit || _shuttingDown) {
return;
}

Expand All @@ -113,7 +116,7 @@ - (void)requestCommit {
_pendingCommit = YES;
if (_waiting) { // BeginResize is in progress, interrupt it and schedule commit call
_condBlockRequestCommit.notify_all();
_condBlockBeginResize.wait(lock, [&]() { return !_pendingCommit; });
_condBlockBeginResize.wait(lock, [&]() { return !_pendingCommit || _shuttingDown; });
} else {
// No resize, schedule commit on platform thread and wait until either done
// or interrupted by incoming BeginResize
Expand All @@ -128,8 +131,15 @@ - (void)requestCommit {
_condBlockBeginResize.notify_all();
}
});
_condBlockBeginResize.wait(lock, [&]() { return !_pendingCommit; });
_condBlockBeginResize.wait(lock, [&]() { return !_pendingCommit || _shuttingDown; });
}
}

- (void)shutdown {
std::unique_lock<std::mutex> lock(_mutex);
_shuttingDown = YES;
_condBlockBeginResize.notify_all();
_condBlockRequestCommit.notify_all();
}

@end
6 changes: 6 additions & 0 deletions shell/platform/darwin/macos/framework/Source/FlutterView.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@
*/
- (nonnull FlutterRenderBackingStore*)backingStoreForSize:(CGSize)size;

/**
* Must be called when shutting down. Unblocks raster thread and prevents any further
* synchronization.
*/
- (void)shutdown;

@end
4 changes: 4 additions & 0 deletions shell/platform/darwin/macos/framework/Source/FlutterView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,8 @@ - (void)viewDidChangeBackingProperties {
[_reshapeListener viewDidReshape:self];
}

- (void)shutdown {
[_resizeSynchronizer shutdown];
}

@end