Crash when set CAMetalLayer.presentsWithTransaction=true in background thread

When set metalLayer.presentsWithTransaction = true, and we call drawable.present() in bg thread (our rendering thread is not main thread), the app sometimes will crash with:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.'

Any solution?

Here is the crash stack trace

Application Specific Information:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.'

Last Exception Backtrace:
0   CoreFoundation                  0x000000018c8fde48 0x000000018c8f4000 + 40520
1   libobjc.A.dylib                 0x0000000185bc78d8 0x0000000185bb0000 + 96472
2   CoreAutoLayout                  0x00000001a9304e84 0x00000001a92f7000 + 56964
3   CoreAutoLayout                  0x00000001a92fb9b4 0x00000001a92f7000 + 18868
4   CoreAutoLayout                  0x00000001a92fb8e4 0x00000001a92f7000 + 18660
5   CoreAutoLayout                  0x00000001a92fb670 0x00000001a92f7000 + 18032
6   UIKitCore                       0x000000018eacf284 0x000000018eac9000 + 25220
7   UIKitCore                       0x000000018eacd860 0x000000018eac9000 + 18528
8   QuartzCore                      0x000000018dfa0b0c 0x000000018df97000 + 39692
9   QuartzCore                      0x000000018dfb41c0 0x000000018df97000 + 119232
10  QuartzCore                      0x000000018dfc5534 0x000000018df97000 + 189748
11  QuartzCore                      0x000000018dffa930 0x000000018df97000 + 407856
12  QuartzCore                      0x000000018dfe3bb4 0x000000018df97000 + 314292
13  CoreFoundation                  0x000000018c985d40 0x000000018c8f4000 + 597312
14  CoreFoundation                  0x000000018c90e290 0x000000018c8f4000 + 107152
15  CoreFoundation                  0x000000018c96fc60 0x000000018c8f4000 + 506976
16  CoreFoundation                  0x000000018c974ec0 0x000000018c8f4000 + 528064
17  Flutter                         0x000000010be19acc 0x000000010bb2c000 + 3070668
18  Flutter                         0x000000010be195c8 0x000000010bb2c000 + 3069384
19  libsystem_pthread.dylib         0x00000001da9866cc 0x00000001da985000 + 5836
20  libsystem_pthread.dylib         0x00000001da985ba4 0x00000001da985000 + 2980

Binary Images:
0x000000010bb2c000 - 0x000000010c30bfff Flutter arm64  <4c4c448455553144a17746f7af31d4ec> /private/var/containers/Bundle/Application/B2924516-9912-465A-A74E-74DB5A6026F7/Runner.app/Frameworks/Flutter.framework/Flutter
0x0000000185bb0000 - 0x0000000185bf3e1f libobjc.A.dylib arm64-unknown  <d6ecfb730ca23a21a3a919e450d3b49c> /usr/lib/libobjc.A.dylib
0x000000018c8f4000 - 0x000000018ccd9fff CoreFoundation arm64-unknown  <725e49f4653b39bf9a7a8a3250911ecb> /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
0x000000018df97000 - 0x000000018e2f5fff QuartzCore arm64-unknown  <e0e47b5d2805361d88c4875002b0244d> /System/Library/Frameworks/QuartzCore.framework/QuartzCore
0x000000018eac9000 - 0x00000001902b4fff UIKitCore arm64-unknown  <59cbc9b530ae396ea269a986640001bc> /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore
0x00000001a92f7000 - 0x00000001a933ffff CoreAutoLayout arm64-unknown  <e96465db77983db5bc5851e367946a04> /System/Library/PrivateFrameworks/CoreAutoLayout.framework/CoreAutoLayout
0x00000001da985000 - 0x00000001da990fff libsystem_pthread.dylib arm64-unknown  <f2ba7ec0f75a3345b4f6f7da4979b902> /usr/lib/system/libsystem_pthread.dylib

Crash when set CAMetalLayer.presentsWithTransaction=true in background thread
 
 
Q