Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 9 keyboard: This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes

when I start a third-party keyboard from a text view embedded in a webview, it sometimes will cause the app crash.

some evidence could be found when the app crashing:

  1. there are always a warning as follows, but when the keyboard is showing successfully, the warning maybe shown as well.

""Sep 25 16:44:09 iPhone6-golden XXX[2916] : This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.""

Stack:(
        0   CoreFoundation                      0x00000001836f4f74 <redacted> + 148
        1   libobjc.A.dylib                     0x00000001982e7f80 objc_exception_throw + 56
        2   CoreFoundation                      0x00000001836f4ea4 <redacted> + 0
        3   Foundation                          0x000000018470e5d8 <redacted> + 88
        4   Foundation                          0x0000000184594f3c <redacted> + 56
        5   Foundation                          0x0000000184590afc <redacted> + 260
        6   UIKit                               0x0000000188d4f958 <redacted> + 64
        7   UIKit                               0x0000000188d50470 <redacted> + 244
        8   UIKit                               0x0000000188d6cf44 <redacted> + 108
        9   UIKit                               0x0000000189476798 <redacted> + 268
        10  UIKit                               0x0000000188f4dfcc <redacted> + 176
        11  UIKit                               0x0000000188f3d0b4 <redacted> + 52
        12  UIKit                               0x0000000188c4700c <redacted> + 644
        13  QuartzCore                          0x000000018844df14 <redacted> + 148
        14  QuartzCore                          0x0000000188448b20 <redacted> + 292
        15  QuartzCore                          0x00000001884489e0 <redacted> + 32
        16  QuartzCore                          0x000000018844807c <redacted> + 252
        17  QuartzCore                          0x0000000188447dd0 <redacted> + 516
        18  QuartzCore                          0x0000000188476f48 <redacted> + 236
        19  libsystem_pthread.dylib             0x0000000198cf61e8 <redacted> + 584
        20  libsystem_pthread.dylib             0x0000000198cf5d60 <redacted> + 136
        21  libsystem_pthread.dylib             0x0000000198cf7b48 pthread_sigmask + 0
        22  libsystem_pthread.dylib             0x0000000198cf7aa0 <redacted> + 0
        23  libsystem_pthread.dylib             0x0000000198cf5030 thread_start + 4
    )
  1. It's the app crashed, not the keyboard. You could find the backtrace in the Device Logs from Xcode.

    Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Triggered by Thread: 18 Filtered syslog: None found

    Last Exception Backtrace:
    0   CoreFoundation                  0x183f20f5c __exceptionPreprocess + 124
    1   libobjc.A.dylib                 0x198b13f80 objc_exception_throw + 56
    2   CoreFoundation                  0x183f20e2c +[NSException raise:format:arguments:] + 108
    3   Foundation                      0x184e0ff3c -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 112
    4   UIKit                           0x1897130e8 -[UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:] + 200
    5   UIKit                           0x1897131ac -[UIApplication _systemAnimationFenceCreatingIfNecessary:] + 24
    6   UIKit                           0x1897653cc +[UIWindow _synchronizedDrawingFence] + 116
    7   UIKit                           0x189c137a4 -[_UIRemoteViewController synchronizeAnimationsInActions:] + 124
    8   UIKit                           0x189c0e158 -[_UISizeTrackingView _geometryChanges:forAncestor:] + 540
    9   UIKit                           0x189775fc8 -[UIView _notifyGeometryObserversWithChangeInfo:] + 272
    10  UIKit                           0x1894d36b4 -[UIView setCenter:] + 408
    11  UIKit                           0x18957ea40 -[UIView(Geometry) _applyISEngineLayoutValues] + 600
    12  UIKit                           0x18948e6b8 -[UIView(Geometry) _resizeWithOldSuperviewSize:] + 136
    13  CoreFoundation                  0x183e17ab0 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 132
    14  CoreFoundation                  0x183e179a8 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 308
    15  UIKit                           0x18947d3e8 -[UIView(Geometry) resizeSubviewsWithOldSize:] + 116
    16  UIKit                           0x18957eb88 -[UIView(AdditionalLayoutSupport) _is_layout] + 128
    17  UIKit                           0x18977a210 -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 756
    18  UIKit                           0x18947300c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 644
    19  QuartzCore                      0x188c79f14 -[CALayer layoutSublayers] + 148
    20  QuartzCore                      0x188c74b20 CA::Layer::layout_if_needed(CA::Transaction*) + 292
    21  QuartzCore                      0x188c749e0 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
    22  QuartzCore                      0x188c7407c CA::Context::commit_transaction(CA::Transaction*) + 252
    23  QuartzCore                      0x188c73dd0 CA::Transaction::commit() + 516
    24  QuartzCore                      0x188c6d4bc CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 80
    25  CoreFoundation                  0x183ed7c30 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
    26  CoreFoundation                  0x183ed59d4 __CFRunLoopDoObservers + 372
    27  CoreFoundation                  0x183e04de0 CFRunLoopRunSpecific + 416
    28  WebCore                         0x195a69aa0 RunWebThread(void*) + 456
    29  libsystem_pthread.dylib         0x199523b3c _pthread_body + 156
    30  libsystem_pthread.dylib         0x199523aa0 _pthread_start + 156
    31  libsystem_pthread.dylib         0x199521030 thread_start + 4
    
    Thread 18 name:  WebThread
    Thread 18 Crashed:
    0   libsystem_kernel.dylib          0x000000019945b1e0 __pthread_kill + 8
    1   libsystem_pthread.dylib         0x0000000199524f0c pthread_kill + 112
    2   libsystem_c.dylib               0x00000001993ceb78 abort + 140
    3   libc++abi.dylib                 0x00000001981913f4 __cxa_bad_cast + 0
    4   libc++abi.dylib                 0x00000001981aaf60 std::__terminate(void (*)()) + 44
    5   libc++abi.dylib                 0x00000001981aab10 __cxa_rethrow + 144
    6   libobjc.A.dylib                 0x0000000198b14120 objc_exception_rethrow + 44
    7   CoreFoundation                  0x0000000183e04e68 CFRunLoopRunSpecific + 552
    8   WebCore                         0x0000000195a69aa0 RunWebThread(void*) + 456
    9   libsystem_pthread.dylib         0x0000000199523b3c _pthread_body + 156
    10  libsystem_pthread.dylib         0x0000000199523aa0 _pthread_body + 0
    11  libsystem_pthread.dylib         0x0000000199521030 thread_start + 4
    

From the crash stack, it is obvious that the application is crashed from WebThread, I guess it is updating some UI details when the keyboard is shown.

BUT, everything works well in ios8.*. Can anyone give me some advise on why this happened? or why the webview is so strange and different from iOS8? I can not find any changes from apple's documents.

Thanks in advance.

like image 231
Weizmann Avatar asked Oct 31 '22 18:10

Weizmann


2 Answers

I found that crash problem may caused by the start-time cost of the 3-party keyboard.

I did the following experiments to compare a custom-keyboard with rapidly-start and delayed-start time cost. The only one variable in the two experiments was the start-keyboard-time-costs. The keyboard without any delay seemed very stable(I mean I did not find any crash), but when I delayed the keyboard with about 800ms-1ms, the risk of crash growed rapidly.

So I am wondering the WebThread may have some timers, when your keyboard is showing up(which means the auto layout engine needs to work), it may trigger the webview crash.

like image 160
Weizmann Avatar answered Nov 12 '22 17:11

Weizmann


It is in fact caused by 3rd party keyboards. The best solution I've found is to disable 3rd party keyboards within the app. You can extend the app delegate, and use the following code to detect and prevent 3rd party keyboards:

- (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier {
if ([extensionPointIdentifier isEqualToString: UIApplicationKeyboardExtensionPointIdentifier]) {
    return NO;
}
return YES;

}

like image 24
Pyro Avatar answered Nov 12 '22 15:11

Pyro