This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Commit fcf65a6
committed
iOS: Add null checks on shell dereference
`FlutterEngine` at the `_shell` unique_ptr ivar it owns have different
lifetimes. `_shell` is initialised transitively from
`runWithEntrypoint`, and reset in `[FlutterEngine destroyContext]`,
which is called transitively from `[FlutterviewController dealloc]` via
`[FlutterEngine notifyViewControllerDeallocated]`.
As such, all uses of `_shell` should be checked either via an assertion,
in cases we know the shell should be non-null, or via a runtime null
check in cases where it's expected that it may be null.
Specifically, this guards against a crash that can occur if we get a
CoreAnimation transaction commit callback for an inflight frame just as
we're shutting down the app (or removing the FlutterView in an
add-to-app scenario).
Example stack trace:
```
0 Flutter 0x11b28 -[FlutterEngine platformView] + 53 (weak_ptr.h:53)
1 Flutter 0x11994 -[FlutterEngine updateViewportMetrics:] + 186 (ref_ptr.h:186)
2 Flutter 0x1f854 -[FlutterViewController updateViewportMetricsIfNeeded] + 427 (vector:427)
3 Flutter 0x1f9b8 -[FlutterViewController viewDidLayoutSubviews] + 1411 (FlutterViewController.mm:1411)
4 UIKitCore 0x8c864 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2376
5 QuartzCore 0x1fa0c CA::Layer::layout_if_needed(CA::Transaction*) + 516
6 QuartzCore 0x1ae84c CA::Context::commit_transaction(CA::Transaction*, double, double*) + 516
7 QuartzCore 0x2888 CA::Transaction::commit() + 648
```
Issue: flutter/flutter#1596391 parent 4d00124 commit fcf65a6
File tree
4 files changed
+41
-8
lines changed- shell/platform/darwin/ios/framework/Source
4 files changed
+41
-8
lines changedLines changed: 20 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
324 | 326 | | |
325 | 327 | | |
326 | 328 | | |
327 | 329 | | |
328 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
329 | 333 | | |
330 | 334 | | |
331 | 335 | | |
332 | 336 | | |
333 | | - | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
334 | 340 | | |
335 | 341 | | |
336 | 342 | | |
337 | 343 | | |
338 | | - | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
339 | 347 | | |
340 | 348 | | |
341 | 349 | | |
342 | 350 | | |
343 | | - | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
344 | 354 | | |
345 | 355 | | |
346 | 356 | | |
| |||
392 | 402 | | |
393 | 403 | | |
394 | 404 | | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
395 | 408 | | |
396 | 409 | | |
397 | 410 | | |
| |||
419 | 432 | | |
420 | 433 | | |
421 | 434 | | |
| 435 | + | |
422 | 436 | | |
423 | 437 | | |
424 | 438 | | |
| |||
1224 | 1238 | | |
1225 | 1239 | | |
1226 | 1240 | | |
| 1241 | + | |
1227 | 1242 | | |
1228 | 1243 | | |
1229 | 1244 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
72 | 85 | | |
73 | 86 | | |
74 | 87 | | |
| |||
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
653 | 653 | | |
654 | 654 | | |
655 | 655 | | |
| 656 | + | |
| 657 | + | |
656 | 658 | | |
657 | 659 | | |
658 | 660 | | |
| |||
1822 | 1824 | | |
1823 | 1825 | | |
1824 | 1826 | | |
1825 | | - | |
| 1827 | + | |
1826 | 1828 | | |
1827 | 1829 | | |
1828 | 1830 | | |
| |||
2105 | 2107 | | |
2106 | 2108 | | |
2107 | 2109 | | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
2108 | 2113 | | |
2109 | 2114 | | |
2110 | 2115 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
0 commit comments