I am having an issue where a crash only occurs when the application is installed via HockeyApp, not via Xcode.
This is the report I get from HockeyApp:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (-1970199490 (or possibly larger)) beyond bounds (15)'
MainViewController.m, line 646
Which refers to this line:
for (int i; i < [resultsArray count]; i++) {
if ([[resultsArray[i] valueForKey:#"uniqueId"] isEqualToString:[[NSUserDefaults standardUserDefaults]
stringForKey:#"FbId"]]) {
resultsArray = resultsArray[i];
}
}
Any ideas why I would be getting a crash there when a build is installed via HockeyApp but not via Xcode? I've even tried building the app to a device using both development and distribution certs, but both work fine as long as the build isn't installed via HockeyApp.
I think the issue would be not initializing the value of the i in the for loop.
it should be for (int i=0;....
if it is not initialised, then the value of i would be unpredictable, it could be either null or it could be the value of its memory address.
if you didn't initialise it, then there will be infinite loop (if there is no crash) here as the value of i will be some random negative number -1970199490,
Also even if you do it from xcode, it results in the same behaviour.
Related
I recently changed the deployment target of my app on mac OS X to 10.9 from 10.8. All other things, code, all other settings being the same. And after this change app is crashing on throwing any exception. The error it shows is "libc++abi.dylib: terminating with uncaught exception", though the app is actually built against libstd++.
I made the things really simple, and i wrote the following code in the beginning of main function of my app:
try
{
int i = 5;
throw i;
}
catch (...)
{
int j = 0;
j++;
}
and the app crashes on "throw i;".
The crash stack doesn't give anything either.
here is a snapshot of call stack and code crashing
This code used to work fine last week and the only thing that changed since is the device used (the previous one was iPad mini on ios9.1, current one is an iPad mini running iOS 8.4)
self.minutesArray = [[NSMutableArray alloc] init];
for (int i = 0; i < 10; i++)
{
[self.minutesArray addObject:[NSNumber numberWithInt:i]];
}
now I always get the error:
Terminating app due to uncaught exception 'NSRangeException', reason:
'*** -[NSMutableIndexSet addIndexesInRange:]: Range {2147483647, 1}
exceeds maximum index value of NSNotFound - 1'
I tried to find where the error was from using breakpoints and the only thing I can say for sure is that the for loop is running fine until the last call (when i = 9)
FWIW, I'm using Xcode 7.
What Avi says. The error is not in the code that you are posting.
Set an exception breakpoint in Xcode, then check where the error actually happens.
I have a very peculiar issue.
Recently I added 64bit support to my iOS project (arm64), ever since doing that I started receiving uncaught exceptions for segments of my code inside #try...#catch (I'm using Crashlytics for crash reporting). I managed to reproduce the problem with the following lines of code anywhere in my app (I wrote them inside init of one of my view controllers):
#try {
NSMutableDictionary *m = [[NSMutableDictionary alloc] init];
NSString *s;
m[s] = #"poop";
} #catch (NSException *e) {
NSLog(#"POOP");
}
The exception gets caught by the UncaughtExceptionHandler instead of the #catch clause. I'm confused as to what can cause this. The output in the console:
2015-02-22 19:19:53.525 [391:30650] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: key cannot be nil'
*** First throw call stack:
(0x18823a59c 0x1989400e4 0x1881251f8 0x10011e2f4 0x10011e068 0x10010e480 0x10010db78 0x10010d944 0x1000a8050 0x100075d88 0x100075160 0x100142044 0x100141f6c 0x18c9ecaa0 0x18caa1fb4 0x18caa1eb0 0x18caa134c 0x18caa0ff8 0x18caa0d18 0x18caa0c98 0x18c9e9648 0x18c341994 0x18c33c564 0x18c33c408 0x18c33bc08 0x18c33b98c 0x18cc76dbc 0x18cc77c68 0x18cc75dec 0x1904b162c 0x1881f2a28 0x1881f1b30 0x1881efd30 0x18811d0a4 0x18ca573c8 0x18ca523c0 0x1000747d8 0x198faea08)
libc++abi.dylib: terminating with uncaught exception of type NSException
I tried removing the custom exception handler that I have and disabling Crashlytics, still no success.
As soon as I remove arm64 from ARCHS and VALID_ARCHS the code works and the exception is caught as expected.
Any information will be appreciated!
Small update - our XCTests also started not to catch exceptions, up until now the behaviour only happened on physical 64bit phones.
After a long session of git-bisecting the culprit was the following linker flag
-no_compact_unwind
I Used BlocksKit v2.2.0 which still had that flag even though it stopped using libffi (latest version of BlocksKit removed that unneeded flag). As soon as I removed that linker flag 64bit #try...#catch blocks started to work again.
I still don't have complete understanding of why this behaviour happens but I'm going to dig a bit more and update this thread if I find anything interesting.
phew
On iOS and Objective-C Exceptions are only to be used for un-recoverable programming errors, not for program execution control.
In particular they do not handle catches accross stack frames inthe APIs.
I have some error in my app,
It report in console:
exc:*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array
but it just crashed and terminated, just didn't break on the crash line of code.
Is it a bug or something wrong on my settings ?
I know what is the problem of my code. I just want to know why xcode not break at the line of the code, not just terminated the app running.
Xcode 6.1 Mac OSX 10.10
somewhere in your code, you are trying to access objects within an array but the array is empty. Before accessing elements of array, just check if array is empty or not by using [myArray count].
After upgrading to XCode4 (v. 4.2, 4D199) it seems every time my apps crash while debugging, the debugging points to main(), and the stack is unsymbolicated and useless.
This has been working fine for years, I have no idea what has gone wrong.
I'm using GDB. I also tried the LLDB as per this advice, and it didn't work either (similar, useless stack).
My breakpoints work, I get the full stack, and can inspect variables when my code hits those.
Steps to reproduce:
NB. this happens with my own project, but I'll use Apple's code here to remove that variable from the equation
Download the following sample from Apple: https://developer.apple.com/library/ios/#samplecode/UICatalog/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007710
In the ImagesViewController class, add the following code to the viewDidLoad method (so it will crash – we want it to crash for this test):
// please note: this code is designed to crash! I want it to crash, to highlight my issue with XCode.
NSMutableArray* test = [NSMutableArray new];
[test insertObject:NULL atIndex:0];
Then run the app & hit the 'Images' row.
It crashes with a message like:
2011-12-23 14:07:02.788 UICatalog[13394:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x37bbb8bf 0x316a11e5 0x37b1020f 0x699f 0x34fac7ff 0x34fb8c39 0x34fb8aa9 0x34fb898f 0x34fb815b 0x34fb7f53 0x34fac673 0x34fac349 0x66c1 0x35026565 0x3509ece7 0x31aec943 0x37b8fa63 0x37b8f6c9 0x37b8e29f 0x37b114dd 0x37b113a5 0x3768ffcd 0x34fa1743 0x2459 0x2418)
terminate called throwing an exception(gdb)
View in xcode:
Thanks to brigadir for pointing me to the solution!
It works well. Here's some screenshots for how to solve this for anyone finding my question:
Tap the plus button of the breakpoints tab
Then click Done