Basically the problem is exactly what the title says.
My app works smoothly on the simulator, with no crashes whatsoever. In fact, the previous version is on the app store. I made minor changes here and there and suddenly it started to crash in a very odd place.
I use [NSBundle mainBundle] resourcepath]
in various places in the code to access plist files, images, etc. The first few calls to NSBundle mainBundle]
are totally normal-as expected-, however, at some point it returns...
-[NSBundle < null selector>]: unrecognized selector sent to instance 0x10a0e0
...and crashes on the device. Here is the exact code snippet:
-(void) setImageName:(NSString *)s
{
[imageName release];
imageName = [s copy];
NSLog(@"last line before crash");
NSString *imagePath =[[NSBundle mainBundle] resourcePath];
NSLog(@"Why would it crash before here???");
imagePath = [imagePath stringByAppendingString:imageName];
imageUI = [[UIImage alloc] initWithContentsOfFile:imagePath];
[self setNeedsDisplay];
}
To check if that call is really the problem, I saved resourcePath
into a string in the first ever call to [NSBundle mainbundle]
in the project (the first few calls were totally normal as I stated above) and used that resourcePath
string everywhere I needed [NSbundle mainbundle] and voila! no crashes/ leaks, nothing...
I'm totally confused.. Why would that call crash my app on the device but not the simulator?
Edit: using...
NSArray *array = [NSBundle allBundles];
NSBundle *bundle = [array objectAtIndex:0];
NSString *imagePath = [bundle bundlePath];
...instead of [[NSBundle mainBundle] resourcePath]
works too. I guess somehow I'm doing something affecting this particular call only.
Edit 2: Here is the backtrace when I set a breakpoint in -[NSObject doesNotRecognizeSelector:] :
#0 0x30e27b98 in -[NSObject doesNotRecognizeSelector:]
#1 0x30dacb18 in ___forwarding___
#2 0x30da3840 in __forwarding_prep_0___
#3 0x0000bcfe in -[CustomTableViewCell setImageName:] at CustomTableViewCell.m:93
#4 0x0000499e in -[RootTableViewController tableView:willDisplayCell:forRowAtIndexPath:] at RootTableViewController.m:469
#5 0x3364d5d0 in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:]
#6 0x3364cde0 in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:]
#7 0x335f832c in -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow]
#8 0x335f6514 in -[UITableView layoutSubviews]
#9 0x335f22d8 in -[UIView(CALayerDelegate) _layoutSublayersOfLayer:]
#10 0x32bac1c0 in -[CALayer layoutSublayers]
#11 0x32babedc in CALayerLayoutIfNeeded
#12 0x32bab844 in CA::Context::commit_transaction
#13 0x32bab474 in CA::Transaction::commit
#14 0x32bb35dc in CA::Transaction::observer_callback
#15 0x30da1830 in __CFRunLoopDoObservers
#16 0x30de9346 in CFRunLoopRunSpecific
#17 0x30de8c1e in CFRunLoopRunInMode
#18 0x332e7374 in GSEventRunModal
#19 0x335adc30 in -[UIApplication _run]
#20 0x335ac230 in UIApplicationMain
... Where #3 - CustomTableViewCell.m:93 is NSString *imagePath =[[NSBundle mainBundle] resourcePath]; in the part of the code I posted above.