Skip to content

Commit 0a9ed47

Browse files
authored
Revert "Reland "iOS: Migrate FlutterEngine to ARC" (flutter#55937)" (flutter/engine#55954)
There are still a couple closures where on engine shutdown, the last live reference to FlutterEngine may be on a thread other than the platform thread. Specifically, the profiling data capture callback can result in the last live reference to a FlutterEngine being on a profiling thread, resulting in an assertion failure in the destructor of the PlatformViewsController held by FlutterEngine, because PlatformViewsController holds a WeakPtrFactory whose destructor asserts that it be on the platform thread. See: https://github.com/flutter/engine/blob/f0f29ce37f235e6bf6734643e13932ce4c091311/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm#L511-L515 Backtrace of such a crash: ``` ================================================================= Main Thread Checker: UI API called on a background thread: -[UIView removeFromSuperview] PID: 46919, TID: 333147, Thread name: FlutterEngine.166.profiler, Queue name: com.apple.root.default-qos.overcommit, QoS: 0 Backtrace: 4 libios_test_flutter.dylib 0x000000014b658aed -[FlutterTextInputPlugin dealloc] + 27 5 libobjc.A.dylib 0x00007ff800055228 _ZN11objc_object17sidetable_releaseEbb + 204 6 libios_test_flutter.dylib 0x000000014b63df5a -[FlutterEngine .cxx_destruct] + 135 7 libobjc.A.dylib 0x00007ff800035766 _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 83 8 libobjc.A.dylib 0x00007ff80004ddfc objc_destructInstance + 61 9 CoreFoundation 0x00007ff8004a286b -[NSObject(NSObject) __dealloc_zombie] + 159 10 libios_test_flutter.dylib 0x000000014b635fea -[FlutterEngine dealloc] + 334 11 libobjc.A.dylib 0x00007ff800055228 _ZN11objc_object17sidetable_releaseEbb + 204 12 libios_test_flutter.dylib 0x000000014b63eda9 _ZNSt3_fl10__function6__funcIZ30-[FlutterEngine startProfiler]E3$_0NS_9allocatorIS2_EEFN7flutter13ProfileSampleEvEEclEv + 69 13 libios_test_flutter.dylib 0x000000014bcd8eaa _ZNSt3_fl10__function6__funcIZNK7flutter16SamplingProfiler16SampleRepeatedlyEN3fml9TimeDeltaEE3$_0NS_9allocatorIS6_EEFvvEEclEv + 40 14 libios_test_flutter.dylib 0x000000014b868786 _ZN3fml15MessageLoopImpl10FlushTasksENS_9FlushTypeE + 156 15 libios_test_flutter.dylib 0x000000014b86ecca _ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0_ + 26 16 CoreFoundation 0x00007ff8003ea4a5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20 17 CoreFoundation 0x00007ff8003ea032 __CFRunLoopDoTimer + 801 18 CoreFoundation 0x00007ff8003e97b6 __CFRunLoopDoTimers + 243 19 CoreFoundation 0x00007ff8003e4028 __CFRunLoopRun + 2108 20 CoreFoundation 0x00007ff8003e3409 CFRunLoopRunSpecific + 557 21 libios_test_flutter.dylib 0x000000014b86ee07 _ZN3fml17MessageLoopDarwin3RunEv + 65 22 libios_test_flutter.dylib 0x000000014b8686a4 _ZN3fml15MessageLoopImpl5DoRunEv + 22 23 libios_test_flutter.dylib 0x000000014b86dce5 _ZNSt3_fl10__function6__funcIZN3fml6ThreadC1ERKNS_8functionIFvRKNS3_12ThreadConfigEEEES7_E3$_0NS_9allocatorISC_EEFvvEEclEv + 135 24 libios_test_flutter.dylib 0x000000014b86da87 _ZZN3fml12ThreadHandleC1EONSt3_fl8functionIFvvEEEEN3$_08__invokeEPv + 27 25 libsystem_pthread.dylib 0x000000010d6a818b _pthread_start + 99 26 libsystem_pthread.dylib 0x000000010d6a3ae3 thread_start + 15 2024-10-18 09:31:27.549111-0700 IosUnitTests[46919:333147] [reports] Main Thread Checker: UI API called on a background thread: -[UIView removeFromSuperview] PID: 46919, TID: 333147, Thread name: FlutterEngine.166.profiler, Queue name: com.apple.root.default-qos.overcommit, QoS: 0 Backtrace: 4 libios_test_flutter.dylib 0x000000014b658aed -[FlutterTextInputPlugin dealloc] + 27 5 libobjc.A.dylib 0x00007ff800055228 _ZN11objc_object17sidetable_releaseEbb + 204 6 libios_test_flutter.dylib 0x000000014b63df5a -[FlutterEngine .cxx_destruct] + 135 7 libobjc.A.dylib 0x00007ff800035766 _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 83 8 libobjc.A.dylib 0x00007ff80004ddfc objc_destructInstance + 61 9 CoreFoundation 0x00007ff8004a286b -[NSObject(NSObject) __dealloc_zombie] + 159 10 libios_test_flutter.dylib 0x000000014b635fea -[FlutterEngine dealloc] + 334 11 libobjc.A.dylib 0x00007ff800055228 _ZN11objc_object17sidetable_releaseEbb + 204 12 libios_test_flutter.dylib 0x000000014b63eda9 _ZNSt3_fl10__function6__funcIZ30-[FlutterEngine startProfiler]E3$_0NS_9allocatorIS2_EEFN7flutter13ProfileSampleEvEEclEv + 69 13 libios_test_flutter.dylib 0x000000014bcd8eaa _ZNSt3_fl10__function6__funcIZNK7flutter16SamplingProfiler16SampleRepeatedlyEN3fml9TimeDeltaEE3$_0NS_9allocatorIS6_EEFvvEEclEv + 40 14 libios_test_flutter.dylib 0x000000014b868786 _ZN3fml15MessageLoopImpl10FlushTasksENS_9FlushTypeE + 156 15 libios_test_flutter.dylib 0x000000014b86ecca _ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0_ + 26 16 CoreFoundation 0x00007ff8003ea4a5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20 17 CoreFoundation 0x00007ff8003ea032 __CFRunLoopDoTimer + 801 18 CoreFoundation 0x00007ff8003e97b6 __CFRunLoopDoTimers + 243 19 CoreFoundation 0x00007ff8003e4028 __CFRunLoopRun + 2108 20 CoreFoundation 0x00007ff8003e3409 CFRunLoopRunSpecific + 557 21 libios_test_flutter.dylib 0x000000014b86ee07 _ZN3fml17MessageLoopDarwin3RunEv + 65 22 libios_test_flutter.dylib 0x000000014b8686a4 _ZN3fml15MessageLoopImpl5DoRunEv + 22 23 libios_test_flutter.dylib 0x000000014b86dce5 _ZNSt3_fl10__function6__funcIZN3fml6ThreadC1ERKNS_8functionIFvRKNS3_12ThreadConfigEEEES7_E3$_0NS_9allocatorISC_EEFvvEEclEv + 135 24 libios_test_flutter.dylib 0x000000014b86da87 _ZZN3fml12ThreadHandleC1EONSt3_fl8functionIFvvEEEEN3$_08__invokeEPv + 27 25 libsystem_pthread.dylib 0x000000010d6a818b _pthread_start + 99 26 libsystem_pthread.dylib 0x000000010d6a3ae3 thread_start + 15 IosUnitTests(47009,0x10ec76240) malloc: enabling scribbling to detect mods to free blocks IosUnitTests(47009) MallocStackLogging: could not tag MSL-related memory as no_footprint, so those pages will be included in process footprint - (null) IosUnitTests(47009) MallocStackLogging: stack logs being written to /private/tmp/stack-logs.47009.1057b6000.IosUnitTests.0o4HgN.index IosUnitTests(47009) MallocStackLogging: recording malloc and VM allocation stacks to disk using standard recorder IosUnitTests(47009) MallocStackLogging: process 46919 no longer exists, stack logs deleted from /tmp/stack-logs.46919.10d1fc000.IosUnitTests.kFionm.index ``` This reverts commit 530a9f8. ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [X] I updated/added relevant documentation (doc comments with `///`). - [X] I signed the [CLA]. - [X] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent cf61b19 commit 0a9ed47

File tree

6 files changed

+379
-293
lines changed

6 files changed

+379
-293
lines changed

engine/src/flutter/shell/platform/darwin/ios/BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ source_set("flutter_framework_source_arc") {
7070
"framework/Source/FlutterDartVMServicePublisher.mm",
7171
"framework/Source/FlutterEmbedderKeyResponder.h",
7272
"framework/Source/FlutterEmbedderKeyResponder.mm",
73-
"framework/Source/FlutterEngine.mm",
7473
"framework/Source/FlutterEngineGroup.mm",
75-
"framework/Source/FlutterEngine_Internal.h",
7674
"framework/Source/FlutterHeadlessDartRunner.mm",
7775
"framework/Source/FlutterKeyPrimaryResponder.h",
7876
"framework/Source/FlutterKeySecondaryResponder.h",
@@ -188,6 +186,8 @@ source_set("flutter_framework_source") {
188186
# iOS embedder is migrating to ARC.
189187
# New files are highly encouraged to be in ARC.
190188
# To add new files in ARC, add them to the `flutter_framework_source_arc` target.
189+
"framework/Source/FlutterEngine.mm",
190+
"framework/Source/FlutterEngine_Internal.h",
191191
"framework/Source/FlutterViewController.mm",
192192
"framework/Source/FlutterViewController_Internal.h",
193193
"platform_view_ios.h",

0 commit comments

Comments
 (0)