Skip to content

iOS: Engine is accessing UI state from background threads #41798

@gaaclarke

Description

@gaaclarke

When running an iOS app I'm getting messages like this:

Main Thread Checker: UI API called on a background thread: -[UIView layer]
PID: 64699, TID: 3927635, Thread name: io.flutter.1.gpu, Queue name: com.apple.root.default-qos.overcommit, QoS: 0
Backtrace:
4   Flutter                             0x00000001031d7b86 -[FlutterView createSurfaceWithResourceGLContext:] + 54
5   Flutter                             0x000000010320e709 _ZNK7flutter15PlatformViewIOS16CreateIOSSurfaceEv + 697
6   Flutter                             0x000000010320f0d6 _ZN7flutter15PlatformViewIOS22CreateRenderingSurfaceEv + 70
7   Flutter                             0x0000000103375e87 _ZZN7flutter12PlatformView13NotifyCreatedEvENK3$_0clEv + 39
8   Flutter                             0x0000000103375e3d _ZNSt3__18__invokeIRZN7flutter12PlatformView13NotifyCreatedEvE3$_0JEEEDTclclsr3std3__1E7forwardIT_Efp_Espclsr3std3__1E7forwardIT0_Efp0_EEEOS5_DpOS6_ + 29
9   Flutter                             0x0000000103375ded _ZNSt3__128__invoke_void_return_wrapperIvE6__callIJRZN7flutter12PlatformView13NotifyCreatedEvE3$_0EEEvDpOT_ + 29
10  Flutter                             0x0000000103374d01 _ZNSt3__110__function6__funcIZN7flutter12PlatformView13NotifyCreatedEvE3$_0NS_9allocatorIS4_EEFvvEEclEv + 33
11  Flutter                             0x000000010324d8d5 _ZNKSt3__18functionIFvvEEclEv + 53
12  Flutter                             0x000000010325ad23 _ZN3fml15MessageLoopImpl10FlushTasksENS_9FlushTypeE + 211
13  Flutter                             0x000000010325ac0a _ZN3fml15MessageLoopImpl18RunExpiredTasksNowEv + 26
14  Flutter                             0x00000001032718c5 _ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0_ + 37
15  CoreFoundation                      0x0000000109acb3e4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
16  CoreFoundation                      0x0000000109acaff2 __CFRunLoopDoTimer + 1026
17  CoreFoundation                      0x0000000109aca85a __CFRunLoopDoTimers + 266
18  CoreFoundation                      0x0000000109ac4efc __CFRunLoopRun + 2220
19  CoreFoundation                      0x0000000109ac4302 CFRunLoopRunSpecific + 626
20  Flutter                             0x0000000103271bfc _ZN3fml17MessageLoopDarwin3RunEv + 316
21  Flutter                             0x000000010325ab52 _ZN3fml15MessageLoopImpl5DoRunEv + 66
22  Flutter                             0x0000000103259aed _ZN3fml11MessageLoop3RunEv + 29
23  Flutter                             0x000000010326e681 _ZZN3fml6ThreadC1ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEENK3$_0clEv + 113
24  Flutter                             0x000000010326e5cd _ZNSt3__18__invokeIZN3fml6ThreadC1ERKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEE3$_0JEEEDTclclsr3std3__1E7forwardIT_Efp_Espclsr3std3__1E7forwardIT0_Efp0_EEEOSC_DpOSD_ + 29
25  Flutter                             0x000000010326e575 _ZNSt3__116__thread_executeINS_10unique_ptrINS_15__thread_structENS_14default_deleteIS2_EEEEZN3fml6ThreadC1ERKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEE3$_0JEJEEEvRNS_5tupleIJT_T0_DpT1_EEENS_15__tuple_indicesIJXspT2_EEEE + 37
26  Flutter                             0x000000010326e1e3 _ZNSt3__114__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEZN3fml6ThreadC1ERKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEE3$_0EEEEEPvSJ_ + 99
27  libsystem_pthread.dylib             0x000000010d9a52eb _pthread_body + 126
28  libsystem_pthread.dylib             0x000000010d9a8249 _pthread_start + 66
29  libsystem_pthread.dylib             0x000000010d9a440d thread_start + 13

It appears we are accessing the layer here from the GPU thread which we shouldn't be doing: https://github.com/flutter/engine/blob/aa8fcbb65283bfd8ab37475043ae2ac8fe8671f4/shell/platform/darwin/ios/framework/Source/FlutterView.mm#L106

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: regressionIt was better in the past than it is nowengineflutter/engine related. See also e: labels.platform-iosiOS applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions