react-native-keyboard-controller: iOS: Crash on @objc func windowDidBecomeHidden(_: Notification) { removeKVObserver() }

Describe the bug

We have a crash that occurs on iOS when reading the reanimated keyboard height.

Code snippet

  const { height: keyboardHeight } = useReanimatedKeyboardAnimation()

Repo for reproducing It’s in our main application. I can’t provided a project to reproduce at this time.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots CleanShot 2023-05-15 at 14 15 03@2x

mobile[62515:8433225] *** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <KeyboardMovementObserver 0x600007c9cba0> for the key path "center" from <UIInputSetHostView 0x1342e19e0> because it is not registered as an observer.'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000180437330 __exceptionPreprocess + 172
	1   libobjc.A.dylib                     0x0000000180051274 objc_exception_throw + 56
	2   Foundation                          0x0000000180b2f1e0 -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 616
	3   Foundation                          0x0000000180b2f5bc -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 132
	4   Foundation                          0x0000000180b2f4d0 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:] + 184
	5   mobile                              0x00000001033eaf6c $s32react_native_keyboard_controller24KeyboardMovementObserverC16removeKVObserver33_98D42DC26656EA4CABF65DBC7E7C9563LLyyF + 192
	6   mobile                              0x00000001033eabb4 $s32react_native_keyboard_controller24KeyboardMovementObserverC21windowDidBecomeHiddenyy10Foundation12NotificationVF + 36
	7   mobile                              0x00000001033eac38 $s32react_native_keyboard_controller24KeyboardMovementObserverC21windowDidBecomeHiddenyy10Foundation12NotificationVFTo + 120
	8   CoreFoundation                      0x000000018036bff8 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 140
	9   CoreFoundation                      0x000000018036bf1c ___CFXRegistrationPost_block_invoke + 84
	10  CoreFoundation                      0x000000018036b424 _CFXRegistrationPost + 404
	11  CoreFoundation                      0x000000018036ae10 _CFXNotificationPost + 664
	12  Foundation                          0x0000000180b5309c -[NSNotificationCenter postNotificationName:object:userInfo:] + 88
	13  UIKitCore                           0x0000000116dd3314 -[UIWindow _setHidden:forced:] + 680
	14  UIKitCore                           0x0000000116c380ec -[_UIRemoteKeyboards setWindowEnabled:force:] + 324
	15  UIKitCore                           0x0000000116c3a6b4 -[_UIRemoteKeyboards setWindowLevel:sceneLevel:forResponder:] + 588
	16  UIKitCore                           0x000000011683f8f8 -[UIKeyboardSceneDelegate setWindowLevel:sceneLevel:forResponder:] + 144
	17  UIKitCore                           0x000000011684048c -[UIKeyboardSceneDelegate setTextEffectsWindowLevelForInputView:responder:] + 864
	18  UIKitCore                           0x0000000116843cc4 -[UIKeyboardSceneDelegate setKeyWindowSceneInputViews:animationStyle:] + 524
	19  UIKitCore                           0x0000000116843a84 -[UIKeyboardSceneDelegate setInputViews:animationStyle:] + 132
	20  UIKitCore                           0x0000000116844a54 -[UIKeyboardSceneDelegate setInputViews:animated:] + 72
	21  UIKitCore                           0x0000000116844aa4 -[UIKeyboardSceneDelegate setInputViews:] + 52
	22  UIKitCore                           0x0000000116842b48 __102-[UIKeyboardSceneDelegate _reloadInputViewsForKeyWindowSceneResponder:force:fromBecomeFirstResponder:]_block_invoke.314 + 24
	23  UIKitCore                           0x0000000116c10d0c __65-[UIPeripheralHost(UIKitInternal) queueDelayedTask:forKey:delay:]_block_invoke + 156
	24  libdispatch.dylib                   0x0000000106bb1d50 _dispatch_client_callout + 16
	25  libdispatch.dylib                   0x0000000106bb5208 _dispatch_continuation_pop + 756
	26  libdispatch.dylib                   0x0000000106bcc8d4 _dispatch_source_invoke + 1676
	27  libdispatch.dylib                   0x0000000106bc2634 _dispatch_main_queue_drain + 848
	28  libdispatch.dylib                   0x0000000106bc22d4 _dispatch_main_queue_callback_4CF + 40
	29  CoreFoundation                      0x000000018039a784 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
	30  CoreFoundation                      0x0000000180394de4 __CFRunLoopRun + 1912
	31  CoreFoundation                      0x0000000180394254 CFRunLoopRunSpecific + 584
	32  GraphicsServices                    0x0000000188eb7c9c GSEventRunModal + 160
	33  UIKitCore                           0x0000000116d9aff0 -[UIApplication _run] + 868
	34  UIKitCore                           0x0000000116d9ef3c UIApplicationMain + 124
	35  mobile                              0x00000001027f7ed8 main + 96
	36  dyld                                0x0000000106579514 start_sim + 20
	37  ???                                 0x0000000106699f28 0x0 + 4402552616
	38  ???                                 0x3a17800000000000 0x0 + 4185955116152520704
)

Smartphone (please complete the following information):

  • iPhone 14 Pro, iOS 16.4, Xcode 14.3

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16 (11 by maintainers)

Commits related to this issue

Most upvoted comments

@kirillzyusko it seems to be extremely rare - we had a few reports early on, so I wasn’t sure at first. I’ll bump the library to latest and report back 👍 Thanks for all of your help and work on this lib. It’s been great!

Awesome @cgav Glad to know the fix is actually working! I’m going to merge this PR within this week and prepare a new release, since it’s quite impactful change 😎

@gtokman could you please check whether #157 fixes the problem?

@kirillzyusko I had the same issue and applying the patch from your PR fixes the crash for me. Thank you 👍

@bcgilliom can you please test 1.11.0 and if it’s still reproducible, then open a new issue? 🙏

And maybe you can shed some light on additional aspects, such as how frequently it happens, how much users are affected (in percentage, like 0.02% or smth like that), and maybe when it happens (maybe user navigated from modal screen to non-modal or something else)?

@kirillzyusko Thanks for the info. I will downgrade for now and keep a close eye on this.

Feel free to tag me if there’s anything I can do to help out.

@kirillzyusko yes, on the latest version of the library and 2.14 for reanimated.

@gtokman I guess it happens on latest version of the library, right?

As an intermediate solution I can suggest to revert back to 1.4.4

In a meantime I’ll try to find a solution and provide a fix 🙂