Modal with topBar title component crashes app when dismissed (iOS debug build)
🐛 Bug Report
If a modal has a custom title component, the app crashes when the modal is dismissed. I'm only seeing this crash so far in debug builds, not release builds.
stack trace:
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
frame #0: 0x00007fff2017689f libobjc.A.dylib`object_isClass + 8
frame #1: 0x00007fff207c2844 Foundation`KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED + 50
frame #2: 0x00007fff207be9b3 Foundation`NSKeyValueWillChangeWithPerThreadPendingNotifications + 240
frame #3: 0x00007fff27b1d8c9 QuartzCore`CA::Layer::begin_change(CA::Transaction*, unsigned int, objc_object*, objc_object*&) + 211
frame #4: 0x00007fff27b25857 QuartzCore`CA::Layer::remove_sublayer(CA::Transaction*, CALayer*) + 85
frame #5: 0x00007fff27b261b6 QuartzCore`CA::Layer::remove_from_superlayer() + 134
frame #6: 0x00007fff24bdfc1b UIKitCore`-[UIView(Hierarchy) removeFromSuperview] + 142
frame #7: 0x00007fff24bc764f UIKitCore`-[UIView dealloc] + 446
* frame #8: 0x000000010fe208e3 playground`-[RCTView dealloc](self=0x00007f9aed65ee00, _cmd="dealloc") at RCTView.m:968:1
frame #9: 0x00007fff20321ea0 CoreFoundation`__RELEASE_OBJECTS_IN_THE_ARRAY__ + 119
frame #10: 0x00007fff20321de2 CoreFoundation`-[__NSArrayM dealloc] + 278
frame #11: 0x00007fff2018f834 libobjc.A.dylib`objc_object::sidetable_release(bool, bool) + 174
frame #12: 0x00007fff2019101b libobjc.A.dylib`AutoreleasePoolPage::releaseUntil(objc_object**) + 175
frame #13: 0x00007fff20190f0a libobjc.A.dylib`objc_autoreleasePoolPop + 185
frame #14: 0x00007fff20430a07 CoreFoundation`_CFAutoreleasePoolPop + 22
frame #15: 0x00007fff2038f223 CoreFoundation`__CFRunLoopPerCalloutARPEnd + 41
frame #16: 0x00007fff2038a677 CoreFoundation`__CFRunLoopRun + 2742
frame #17: 0x00007fff203896d6 CoreFoundation`CFRunLoopRunSpecific + 567
frame #18: 0x00007fff2c257db3 GraphicsServices`GSEventRunModal + 139
frame #19: 0x00007fff24696cf7 UIKitCore`-[UIApplication _run] + 912
frame #20: 0x00007fff2469bba8 UIKitCore`UIApplicationMain + 101
frame #21: 0x000000010fba4a8f playground`main(argc=1, argv=0x00007ffee005f258) at main.m:27:20
frame #22: 0x00007fff2025a3e9 libdyld.dylib`start + 1
frame #23: 0x00007fff2025a3e9 libdyld.dylib`start + 1
Have you read the Contributing Guidelines on issues?
Yes
To Reproduce
- Configure a modal with topBar.title.component
- Call showModal()
- Call dismissModal()
Expected behavior
App should not crash
Actual Behavior
App crashes
Your Environment
- React Native Navigation version: 7.11.2
- React Native version: 0.63.2
- Platform(s) (iOS, Android, or both?): iOS
- Device info (Simulator/Device? OS version? Debug/Release?): iOS Simulator, iOS 14.4, debug build
Reproducible Demo
demo in playground app: https://github.com/brsaylor2/react-native-navigation/commit/704350300f5cb8a0f75edbcbc4128e2cb0ca5407
- Go to Navigation tab
- Tap "Modal"
- Dismiss modal
This has started happening to me as well on 7.11.1 and RN 0.63.4 (was also present on RN 0.61.1).
My steps to reproduce are to add a component into one of the rightButtons or leftButtons (based on OP, seems to be any component in the topBar in a modal).
Only crashes after the first close however. So: present the modal, close the modal, present the modal again, close the modal, crash Thread 1: EXC_BAD_ACCESS (code=1, address=0x1c)
When the component is removed from the topBar, the issue no longer occurs and the modal can be closed multiple times without issue.
The component is pretty simple at the moment for test purposes:
const MyDumbComponent = (props) => {
return (
<Text>Button</Text>
);
};
And is being registered immediately like so:
Navigation.registerComponent( 'MyDumbComponent',() => MyDumbComponent)
And is being called using:
Navigation.showModal( {
stack: {
id: 'ModalStack',
name: 'ModalStack',
children: [{
component: {
name: 'MyTestScreen',
id: 'MyTestScreen',
options: {
topBar: {
visible: true,
drawBehind: false,
rightButtons: [
{
id: 'dumb',
component: {
id: 'dumb',
name: 'MyDumbComponent',
},
},
],
}
}
}
}]
}
})
Edit: This also seems to happen on non-modal layouts too.
I can confirm that I don't see this bug on 7.11.0. git bisect points to d4aa63d81dfc447c24048795c7bcd4062640bf0c as the culprit.
Can also confirm that reverting that commit via patch-package fixes the bug in my app.
Hi guys, sorry for the inconvenience, could you please verify that this PR fixes it?
@yogevbd Yes, that seems to fix it. Thanks!