Check weak pointer to avoid potential use-after-free crash (#30396)
diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
index 708d3fa..5e45a02 100644
--- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
+++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
@@ -518,15 +518,17 @@
FML_DCHECK(RasterTaskRunner->RunsTasksOnCurrentThread());
// Get callback on raster thread and jump back to platform thread.
platformTaskRunner->PostTask([weakSelf]() {
- fml::scoped_nsobject<FlutterViewController> flutterViewController(
- [(FlutterViewController*)weakSelf.get() retain]);
- if (flutterViewController) {
- if (flutterViewController.get()->_splashScreenView) {
- [flutterViewController removeSplashScreenView:^{
+ if (weakSelf) {
+ fml::scoped_nsobject<FlutterViewController> flutterViewController(
+ [(FlutterViewController*)weakSelf.get() retain]);
+ if (flutterViewController) {
+ if (flutterViewController.get()->_splashScreenView) {
+ [flutterViewController removeSplashScreenView:^{
+ [flutterViewController callViewRenderedCallback];
+ }];
+ } else {
[flutterViewController callViewRenderedCallback];
- }];
- } else {
- [flutterViewController callViewRenderedCallback];
+ }
}
}
});