Getting NSInvalidArgumentException crash on [__NSArrayM insertObject:atIndex:]

Hi All,


We are getting following crash once we have started submitting our app from Xcode 10. Below is the stack trace.

The crash is random and not reproducible. It will be great if anyone from apple support team can help us to identify and solve the crash.


Fatal Exception: NSInvalidArgumentException

0 CoreFoundation 0x1bc8823a8 __exceptionPreprocess

1 libobjc.A.dylib 0x1bba87d00 objc_exception_throw

2 CoreFoundation 0x1bc7f9870 _CFArgv

3 CoreFoundation 0x1bc767410 -[__NSArrayM insertObject:atIndex:]

4 TargetActClient 0x1067d7078 (Missing)

5 libdispatch.dylib 0x1bc290304 _dispatch_call_block_and_release

6 libdispatch.dylib 0x1bc291884 _dispatch_client_callout

7 libdispatch.dylib 0x1bc298dd4 _dispatch_lane_serial_drain

8 libdispatch.dylib 0x1bc299918 _dispatch_lane_invoke

9 libdispatch.dylib 0x1bc2a1cc0 _dispatch_workloop_worker_thread

10 libsystem_pthread.dylib 0x1bc48ca98 _pthread_wqthread

11 libsystem_pthread.dylib 0x1bc492dc4 start_wqthread


Let us know if anything else needed.

Replies

This may indicate you're trying to insert a nil value into an array. (I don't think it indicates that your array index is out of range. IIRC there is a different error for that.)


Note that it may actually be telling you that you are accessing the array in a thread-unsafe way, perhaps by mutating it on two threads at once. That could easily result in an exception like this.


The fact that you "suddenly" started getting an error doesn't mean much by itself. Any change in compiler/linker/etc could result in a slight timing change in your code that exposes a previous potential problem.


You should try running the standard tools, such as the code analyzer, and turn on thread sanitizer. Also, if you symbolicate the crash log (presuming TargetActClient is your code, or at least code you have source for), you might be able to reason about what's going on at that point in the code.