Unblock FlutterResizeSynchronizer on engine shutdown (flutter/engine#24264)

This commit is contained in:
Matej Knopp
2021-02-16 21:56:01 +01:00
committed by GitHub
parent 4a5659129b
commit 68bb09e4ec
5 changed files with 34 additions and 5 deletions

View File

@@ -489,6 +489,10 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
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);

View File

@@ -75,4 +75,9 @@
*/
- (void)requestCommit;
/**
* Called when shutting down. Unblocks everything and prevents any further synchronization.
*/
- (void)shutdown;
@end

View File

@@ -34,6 +34,9 @@
// Target size for resizing.
CGSize _newSize;
// if YES prevents all synchronization
BOOL _shuttingDown;
__weak id<FlutterResizeSynchronizerDelegate> _delegate;
}
@end
@@ -54,7 +57,7 @@
return;
}
if (!_receivedFirstFrame) {
if (!_receivedFirstFrame || _shuttingDown) {
// No blocking until framework produces at least one frame
notify();
return;
@@ -77,7 +80,7 @@
_waiting = YES;
_condBlockRequestCommit.wait(lock, [&] { return _pendingCommit; });
_condBlockRequestCommit.wait(lock, [&] { return _pendingCommit || _shuttingDown; });
[_delegate resizeSynchronizerFlush:self];
[_delegate resizeSynchronizerCommit:self];
@@ -104,7 +107,7 @@
- (void)requestCommit {
std::unique_lock<std::mutex> lock(_mutex);
if (!_acceptingCommit) {
if (!_acceptingCommit || _shuttingDown) {
return;
}
@@ -113,7 +116,7 @@
_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
@@ -128,8 +131,15 @@
_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

View File

@@ -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

View File

@@ -124,4 +124,8 @@
[_reshapeListener viewDidReshape:self];
}
- (void)shutdown {
[_resizeSynchronizer shutdown];
}
@end