question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Array index out of bounds

See original GitHub issue

Description

Hello, I am not super well versed in analyzing crash reports. But we are experiencing a fair number of crashes which is being caused from the RNSScreen.m file within this package. I have included the last execution backtrace below which indicates what is happening. Seems like the line: https://github.com/software-mansion/react-native-screens/blob/main/ios/RNSScreen.m#L612

if (currentIndex > 0 && [self.view.reactSubviews[0] isKindOfClass:[RNSScreenStackHeaderConfig class]]) {

is causing the out of bounds index. I am guessing ‘self.view.reactSubviews[0]’ is where the out of bounds index is happening.

Last Exception Backtrace:
0   CoreFoundation                	0x1811390fc __exceptionPreprocess + 220 (NSException.m:200)
1   libobjc.A.dylib               	0x199973d64 objc_exception_throw + 60 (objc-exception.mm:565)
2   CoreFoundation                	0x181242564 _CFThrowFormattedException + 116 (CFObject.m:2072)
3   CoreFoundation                	0x1810d7f00 -[__NSArrayM objectAtIndexedSubscript:] + 188 (NSArrayM.m:309)
4   WeSponsoredApp                	0x1021ea448 -[RNSScreen hideHeaderIfNecessary] + 240 (RNSScreen.m:590)
5   WeSponsoredApp                	0x1021ea2b0 -[RNSScreen viewWillAppear:] + 216 (RNSScreen.m:567)
6   UIKitCore                     	0x1836f3bc8 -[UIViewController _setViewAppearState:isAnimating:] + 664 (UIViewController.m:5522)
7   UIKitCore                     	0x1838233d0 -[UIViewController __viewWillAppear:] + 120 (UIViewController.m:5654)
8   UIKitCore                     	0x1838c265c -[UINavigationController _startCustomTransition:] + 1316 (UINavigationController.m:2082)
9   UIKitCore                     	0x183a20e54 -[UINavigationController _startDeferredTransitionIfNeeded:] + 696 (UINavigationController.m:7519)
10  UIKitCore                     	0x1838f5ea4 -[UINavigationController __viewWillLayoutSubviews] + 168 (UINavigationController.m:7826)
11  UIKitCore                     	0x18381c4a4 -[UILayoutContainerView layoutSubviews] + 228 (UILayoutContainerView.m:88)
12  UIKit                         	0x1f26b0128 -[UILayoutContainerViewAccessibility layoutSubviews] + 52 (UILayoutContainerViewAccessibility.m:132)
13  UIKitCore                     	0x1836d4798 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2620 (UIView.m:18348)
14  QuartzCore                    	0x184e37138 CA::Layer::layout_if_needed(CA::Transaction*) + 536 (CALayer.mm:10038)
15  QuartzCore                    	0x184e29958 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 144 (CALayer.mm:2480)
16  QuartzCore                    	0x184e3df80 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 524 (CAContextInternal.mm:2586)
17  QuartzCore                    	0x184e46874 CA::Transaction::commit() + 680 (CATransactionInternal.mm:449)
18  QuartzCore                    	0x184e290bc CA::Transaction::flush_as_runloop_observer(bool) + 100 (CATransactionInternal.mm:941)
19  UIKitCore                     	0x183a8acc0 _UIApplicationFlushCATransaction + 76 (UIApplication.m:0)
20  UIKitCore                     	0x183d255fc _UIUpdateSequenceRun + 84 (_UIUpdateSequence.mm:112)
21  UIKitCore                     	0x1843a15b0 schedulerStepScheduledMainSection + 144 (_UIUpdateCycleScheduler.m:1174)
22  UIKitCore                     	0x1843a0ba0 runloopSourceCallback + 60 (_UIUpdateCycleScheduler.m:1262)
23  CoreFoundation                	0x18115b0d0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 (CFRunLoop.c:1972)
24  CoreFoundation                	0x18116bd90 __CFRunLoopDoSource0 + 208 (CFRunLoop.c:2016)
25  CoreFoundation                	0x1810a6098 __CFRunLoopDoSources0 + 268 (CFRunLoop.c:2053)
26  CoreFoundation                	0x1810ab8a4 __CFRunLoopRun + 820 (CFRunLoop.c:2951)
27  CoreFoundation                	0x1810bf468 CFRunLoopRunSpecific + 600 (CFRunLoop.c:3268)
28  GraphicsServices              	0x19cc4a38c GSEventRunModal + 164 (GSEvent.c:2200)
29  UIKitCore                     	0x183a61088 -[UIApplication _run] + 1100 (UIApplication.m:3493)
30  UIKitCore                     	0x1837df958 UIApplicationMain + 2092 (UIApplication.m:5046)
31  WeSponsoredApp                	0x10202feb0 main + 88 (main.m:7)
32  dyld                          	0x10293daa4 start + 520 (dyldMain.cpp:879)

Screenshots

Steps To Reproduce

I am currently trying to reproduce, but am having trouble doing it locally. Looking through our analytics, it seems like it is happening when navigation.goBack() is being called. I will update this ticket if I find anymore details.

Expected behavior

App does not crash

Actual behavior

App crases

Reproduction

I am currently trying to reproduce, but am having trouble doing it locally. Looking through our analytics, it seems like it is happening when navigation.goBack() is being called. I will update this ticket if I find anymore details.

Platform

  • iOS
  • Android
  • Web
  • Windows
  • tvOS

Workflow

  • Managed workflow
  • Bare workflow

Package versions

package version
react-native 0.66.0
@react-navigation/native ^6.0.6
@react-navigation/native-stack ^6.2.5
react-native-screens ^3.8.0
react-native-safe-area-context ^3.3.2
react-native-gesture-handler ^1.10.3
react-native-reanimated ^2.3.0-beta.2
expo n/a

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
cltnschlossercommented, May 16, 2022

I’ve done no investigation yet, but seeing this in a new app release. Version 3.10.1 of react-native-screens. The previous release didn’t have any occurrences of this crash (Also version 3.10.1).

I’ll update here if I find what changed to cause this.

0reactions
kkafarcommented, Aug 13, 2022

This should be fixed with changes introduced by me in #1491, as reactSubviews array is now being checked against being empty before accessing the first item.

Notify me if the problem is not solved with latest react-native-screens version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Array Index Out Of Bounds Exception in Java - GeeksforGeeks
The index of an array is an integer value that has value in the interval [0, n-1], where n is the size of...
Read more >
How to fix array index out of bounds error? - Stack Overflow
1. Your counter should be the position in the array and not the value of that position. · This looks like trouble int...
Read more >
What is the ArrayIndexOutOfBounds exception in Java?
The ArrayIndexOutOfBounds exception is thrown if a program tries to access an array index that is negative, greater than, or equal to the...
Read more >
Array index is out of bounds - Microsoft Community
Trying to open an email in outlook 2016 and it tells me the array index may be out of bounds. Can anyone help?...
Read more >
Array index out of bounds — CodeQL query help documentation
Array index out of bounds ¶ ... When accessing an array element, one must ensure that the index is less than the length...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found