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.
Related
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.
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
I recently picked up doing iOS development.
I am new to the whole thing, so please forgive my ignorance.
I ran into an issue in my app where when i start a stream (like streaming live audio), the app crashes (ipod touch 5th gen running iOS 7.1).
I get this error:
Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFConstantString characterAtIndex:]: Range or index out of bounds'.
Can someone help me in diagnosing this issue and possible solutions?
Thanks!!
ironmantis7x
EDIT: Here is the full error message:
2014-06-18 13:18:39.181 miraathradios[845:60b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFConstantString characterAtIndex:]: Range or index out of bounds'
*** First throw call stack:
(0x2f6f0fd3 0x39e3bccf 0x2f6f0f15 0x2f6364f7 0x63c65 0x63b35 0x60a8b 0x300d9c73 0x2f6bc25b 0x2f6bb72b 0x2f6b9f1f 0x2f624f0f 0x2f624cf3 0x34546663 0x31f7016d 0x588a9 0x587f8)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
partial code:
- (JHTickerDirection)detecteDirection:(NSString *) title{
//NSString *letters = #"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
NSCharacterSet *letters = [NSCharacterSet characterSetWithCharactersInString:#"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"];
unichar ch = [title characterAtIndex:6];
if ([letters characterIsMember:ch]) {
return JHTickerDirectionLTR;
}else{
return JHTickerDirectionRTL;
}
}
When debugging, I strongly advise you to add 2 special breakpoints :
One for all exceptions.
And one for all "BAD_ACCESS" errors.
When those 2 breakpoints are enabled, xcode will automatically break on the faulting line instead of directly crashing without giving more informations.
To activate them, follow these steps :
open the breakpoint left tab, and click the "+" button in the bottom left corner.
select Add Exception Breakpoint.
Right click on the new breakpoint, and configure it this way :
Exception : All
Break : On throw
Action : Add Action
Options : leave the box unchecked.
Then add a symbolic break point ("+" button -> Add Symbolic Breakpoint)
Configure the breakpoint this way :
Symbol : malloc_error_break
don't modify all the other options
You're done for starting debugging !
So you're hard-coding the index to look for characterAtIndex: 6.
If the argument "title" passed in is anything shorter (say only 4 characters), or perhaps it's a unicode character split in 2 (like ä split into a and ¨), "ch" could be undefined and "out of range." Perhaps consider looping through "title" by character & seeing if it's within a given range of unicode characters, rather than hard-coding the index & checking against the entire alphabet string.
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
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* +[NSString stringWithUTF8String:]: NULL cString'
* First throw call stack:
(0x374ec8bf 0x362cb1e5 0x374ec7b9 0x374ec7db 0x31dade97 0x278f 0x2c2d 0x307877eb 0x307813bd 0x3074f921 0x3074f3bf 0x3074ed2d 0x36000e13 0x374c0553 0x374c04f5 0x374bf343 0x374424dd 0x374423a5 0x30780457 0x3077d743 0x2439 0x23d0)
terminate called throwing an exception
I just don't understand why it was working until 5 minutes ago testing it on the same thing and now it's not working anymore. What can I do to solve this problem? The application works fine on the simulator.
Your string cString = null..
Fill it.
Where do you get the string? One of the more common reasons for "works on Simulator but not device" is that you are reading from a file and use the wrong case -- device has case-sensitive file systems, but Macs have case-insensitive (typically).
The reason why it didn't work on the device is because I modified the database and for some reason the one on the device was the wrong one which obviously was incompatible with the new code. After I deleted the application from the Ipod and then ran it again it worked just fine.
The reason why I had that specific error is because some variables that were holding database columns were empty.