Cocos2D crashing on iPhone immediately but not in simulator - iphone

I'm trying to test a Cocos2D app on an iPhone, and get this crash that I copied from the console:
cocos2d: CCSpriteFrameCache: Trying to use file 'heroTestSheet.png' as texture
cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
cocos2d: Couldn't add image:heroTestSheet.png in CCTextureCache
cocos2d: CCSpriteFrameCache: Couldn't load texture
cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
cocos2d: Couldn't add image:heroTestSheet.png in CCTextureCache
cocos2d: CCSpriteFrameCache: Frame 'heroFrame1.png' not found
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'
*** Call stack at first throw:
(
0 CoreFoundation 0x3759dc7b __exceptionPreprocess + 114
1 libobjc.A.dylib 0x32d9bee8 objc_exception_throw + 40
2 CoreFoundation 0x3752a951 -[__NSArrayM insertObject:atIndex:] + 136
3 CoreFoundation 0x3752a8bf -[__NSArrayM addObject:] + 34
4 cocosTests 0x0000ce28 -[HeroClass init] + 1544
5 cocosTests 0x0000304c -[DebugZoneLayer init] + 860
6 cocosTests 0x00074e04 +[CCNode node] + 76
7 cocosTests 0x0000c4e4 -[DebugZoneScene init] + 244
8 cocosTests 0x00074e04 +[CCNode node] + 76
9 cocosTests 0x0000c390 +[DebugZoneScene scene] + 100
10 cocosTests 0x00002540 -[cocosTestsAppDelegate applicationDidFinishLaunching:] + 1028
11 UIKit 0x3592502c -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1200
12 UIKit 0x3591ea78 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 396
13 UIKit 0x358d82e4 -[UIApplication handleEvent:withNewEvent:] + 1476
14 UIKit 0x358d7b1c -[UIApplication sendEvent:] + 68
15 UIKit 0x358d73b4 _UIApplicationHandleEvent + 6824
16 GraphicsServices 0x33e77c88 PurpleEventCallback + 1048
17 CoreFoundation 0x3752f5cb __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 28
18 CoreFoundation 0x3752f589 __CFRunLoopDoSource1 + 164
19 CoreFoundation 0x37521835 __CFRunLoopRun + 580
20 CoreFoundation 0x3752150b CFRunLoopRunSpecific + 226
21 CoreFoundation 0x37521419 CFRunLoopRunInMode + 60
22 UIKit 0x3591d554 -[UIApplication _run] + 548
23 UIKit 0x3591a558 UIApplicationMain + 972
24 cocosTests 0x000020c4 main + 100
25 cocosTests 0x0000205c start + 40
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
Running it in the simulator runs fine, but I still get this message in the console when it starts up "CCSpriteFrameCache: Trying to use file 'heroTestSheet.png' as texture"
I suspect that's where the problem starts. Maybe I'm just understanding how my code for my hero sprite subclass should be written. I thought heroTestSheet.png was the texture it was relying on to split up into other images referencing the plist.
Here's my init in my hero subclass:
-(id) init{
self = [super init];
if (!self) {
return nil;
}
_collisWidthFromCtr = 16;
_collisHeightFromCtr = 16;
_collisPushPointsNums = 5;
_travelRectCenterPoints = [[NSMutableArray alloc] init];
_collisPushPoints = [[NSMutableArray alloc] init];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( _collisWidthFromCtr, _collisHeightFromCtr)] atIndex:0];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( _collisWidthFromCtr, 0)] atIndex:1];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( _collisWidthFromCtr,-_collisHeightFromCtr)] atIndex:2];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake( 0, _collisHeightFromCtr)] atIndex:3];
[_collisPushPoints insertObject:[NSValue valueWithCGPoint:CGPointMake(-_collisWidthFromCtr, _collisHeightFromCtr)] atIndex:4];
_rectCheckRes = 32;
_speed = 8;
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:#"heroTestSheet.plist"];
_heroSpriteSheet = [CCSpriteBatchNode batchNodeWithFile:#"heroTestSheet.png"];
//[self addChild:_heroSpriteSheet];
NSMutableArray *heroSpriteFlyAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 2; ++i) {
[heroSpriteFlyAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:#"heroFrame%d.png", i]]];
}
CCAnimation *heroSpriteFlyAnim = [CCAnimation animationWithFrames:heroSpriteFlyAnimFrames delay:0.03f];
_heroSprite = [CCSprite spriteWithSpriteFrameName:#"heroFrame1.png"];
_heroSpriteFlyAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:heroSpriteFlyAnim restoreOriginalFrame:NO]];
[_heroSprite runAction:_heroSpriteFlyAction];
[_heroSpriteSheet addChild:_heroSprite];
return self;
}
Please excuse me if I'm being unclear, so let me know any other info I need to provide. Just posting this for now because I don't know where else to start to solve it and what other info I should provide, and it might be obvious to some other cocos devs whats wrong from what I posted. Thanks

The simulator can be more forgiving than the device. Double check that your file name really is "heroTestSheet.png" and not "HeroTestSheet.png" for example. It is case sensitive on your device.

Figured it out.. it was just the heroTestSheet.png it was trying to use was somehow invalid. I exported in an older photoshop, but I'm not really positive what settings it had. I exported it again from a newer photoshop without any color mange settings, and now it works fine!

I think you image was not added on the project.
You must copy your binary to the resource.
select your target and then select the build phases then copy bundle resource
add you image on that content.
I think it will work.

Related

iPhone App crashes after localization of xib file

I am creating my first iPhone app in which the first screen displays a table view the user selects from. It works before localization using the method below.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
navigationController = [[UINavigationController alloc] init];
[self.window addSubview:[self.navigationController view]];
if(self.selectCategoryViewController == nil)
{
SelectCategoryViewController *viewTwo = [[SelectCategoryViewController alloc] initWithNibName:#"SelectCategoryViewController" bundle:[NSBundle mainBundle]];
self.selectCategoryViewController = viewTwo;
[viewTwo release];
}
[self.navigationController setNavigationBarHidden:YES];//this will hide the navigation bar
[self.navigationController pushViewController:self.selectCategoryViewController animated:YES];
//self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
After I localized it by adding the Japanese localization file and changing the above to this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
navigationController = [[UINavigationController alloc] init];
[self.window addSubview:[self.navigationController view]];
if(self.selectCategoryViewController == nil)
{
NSBundle *myLocalizedBundle=[NSBundle bundleWithPath:[NSString stringWithFormat:[[NSBundle mainBundle]bundlePath],"en.lproj"]];
NSLog(#"the localized bundle is %#",myLocalizedBundle);
SelectCategoryViewController *viewTwo=[[SelectCategoryViewController alloc] initWithNibName:#"SelectCategoryViewController" bundle:myLocalizedBundle];
self.selectCategoryViewController = viewTwo;
[viewTwo release];
}
[self.navigationController setNavigationBarHidden:YES];//this will hide the navigation bar
[self.navigationController pushViewController:self.selectCategoryViewController animated:YES];
[self.window makeKeyAndVisible];
return YES;
}
it crashes with the following error:
√sh.app> (loaded)
2013-02-18 18:04:35.196 PictureEnglish[5529:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFString substringFromIndex:]: Range or index out of bounds'
*** Call stack at first throw:
(
0 CoreFoundation 0x012775a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x013cb313 objc_exception_throw + 44
2 CoreFoundation 0x0122fef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x0122fe6a +[NSException raise:format:] + 58
4 Foundation 0x00033086 -[NSString substringFromIndex:] + 133
5 PictureEnglish 0x00008524 -[SelectCategoryViewController viewDidLoad] + 937
6 UIKit 0x00378089 -[UIViewController view] + 179
7 UIKit 0x00376482 -[UIViewController contentScrollView] + 42
8 UIKit 0x00386f25 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
9 UIKit 0x00385555 -[UINavigationController _layoutViewController:] + 43
10 UIKit 0x00386870 -[UINavigationController _startTransition:fromViewController:toViewController:] + 524
11 UIKit 0x0038132a -[UINavigationController _startDeferredTransitionIfNeeded] + 266
12 UIKit 0x0049c2e9 -[UILayoutContainerView layoutSubviews] + 226
13 QuartzCore 0x010a7a5a -[CALayer layoutSublayers] + 181
14 QuartzCore 0x010a9ddc CALayerLayoutIfNeeded + 220
15 QuartzCore 0x0104f0b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
16 QuartzCore 0x01050294 _ZN2CA11Transaction6commitEv + 292
17 UIKit 0x002ca9c9 -[UIApplication _reportAppLaunchFinished] + 39
18 UIKit 0x002cae83 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 690
19 UIKit 0x002d5617 -[UIApplication handleEvent:withNewEvent:] + 1533
20 UIKit 0x002cdabf -[UIApplication sendEvent:] + 71
21 UIKit 0x002d2f2e _UIApplicationHandleEvent + 7576
22 GraphicsServices 0x01bcf992 PurpleEventCallback + 1550
23 CoreFoundation 0x01258944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
24 CoreFoundation 0x011b8cf7 __CFRunLoopDoSource1 + 215
25 CoreFoundation 0x011b5f83 __CFRunLoopRun + 979
26 CoreFoundation 0x011b5840 CFRunLoopRunSpecific + 208
27 CoreFoundation 0x011b5761 CFRunLoopRunInMode + 97
28 UIKit 0x002ca7d2 -[UIApplication _run] + 623
29 UIKit 0x002d6c93 UIApplicationMain + 1160
30 PictureEnglish 0x00001cec main + 102
31 PictureEnglish 0x00001c7d start + 53
32 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Any suggestions on how I should call the SelectCategoryViewController for the selected language?
This line looks wrong to me:
NSBundle *myLocalizedBundle=[NSBundle bundleWithPath:[NSString stringWithFormat:[[NSBundle mainBundle]bundlePath],"en.lproj"]];
You probably meant something like this:
NSString* path= [[NSBundle mainBundle] pathForResource:#"en" ofType:#"lproj"];
NSBundle* bundle:myLocalizedBundle = [NSBundle bundleWithPath:path];
SelectCategoryViewController *viewTwo = [[SelectCategoryViewController alloc] initWithNibName:#"SelectCategoryViewController" bundle:myLocalizedBundle];
This is discussed more here: Manually loading a different localized nib in iOs
Note that this is only required if you want to do an in-app language selection. Localization should typically use the iOS device's selected language, in which case all this is much more straightforward (you simply let iOS pick the bundle for you).
xcode 5:
i had to clean build, clean build folder,delete derived data, reset simulator, close simulator, close Xcode.
Open project again and it's working.
Problem - This is a problem of project path, I think [self.window makeWindowKeyVisible] can not be able to find a path to your first assigned controller...
Solution - It happens some time, when your project suddenly stopped work, So no worries - just shift your project to other path, or just change the name of folder where actually your project resides and it will started working fine....
It works for me successfully...

Crash presenting modal view controller

I have this crash. It is similar to other threads, but not the same.
I would like to show a modal view controller first the user goes to a specific view controller. Following the hints, I do that on - (void) viewDidAppear:(BOOL)animated, and apply a delay as I saw it's recommended.
- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self performSelector:#selector(presentMyModal) withObject:nil afterDelay:1];
}
- (void) presentModal{
ModalViewController *modal = [[[ModalViewController alloc] init] autorelease];
[self presentModalViewController:modal animated:YES];
}
Afterwards, ramdomly It crashes. I get this message in console:
<Warning>: *** Assertion failure in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:], /SourceCache/UIKit/UIKit-1447.6.4/UIWindowController.m:186
Thu Feb 3 10:00:44 unknown MyApp[1830] <Error>: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempting to begin a modal transition from <UINavigationController: 0x454260> to <ModalViewController: 0x47af00> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed'
*** Call stack at first throw:
(
0 CoreFoundation 0x3759dc7b __exceptionPreprocess + 114
1 libobjc.A.dylib 0x32d9bee8 objc_exception_throw + 40
2 CoreFoundation 0x3759dac3 +[NSException raise:format:arguments:] + 70
3 Foundation 0x351a3e73 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 62
4 UIKit 0x359e92a8 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 208
5 UIKit 0x359e8c98 -[UIViewController presentModalViewController:withTransition:] + 2792
6 UIKit 0x35a7b51c -[UIViewController _tryRecursivelyPresentModalViewController:withTransition:] + 116
7 UIKit 0x359e84c0 -[UIViewController presentModalViewController:withTransition:] + 784
8 UIKit 0x359e8060 -[UIViewController presentModalViewController:animated:] + 96
9 MyApp 0x0005d57f -[MyAppViewController presentMyModal] + 58
10 Foundation 0x351724db __NSFireDelayedPerform + 366
11 CoreFoundation 0x37552305 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 16
12 CoreFoundation 0x37551cd9 __CFRunLoopDoTimer + 988
13 CoreFoundation 0x37521a91 __CFRunLoopRun + 1184
14 CoreFoundation 0x3752150b CFRunLoopRunSpecific + 226
15 CoreFoundation 0x37521419 CFRunLoopRunInMode + 60
16 GraphicsServices 0x33e76d24 GSEventRunModal + 196
17 UIKit 0x3591d57c -[UIApplication _run] + 588
18 UIKit 0x3591a558 UIApplicationMain + 972
19 MyApp 0x0000e75f main + 50
20 MyApp 0x0000e6e8 start + 52
As you can see, I wait until view is appeared. Is this maybe an OS bug? It seems like it tries to present recursively other modal view controllers, provoquing crashes.
Thanks a lot.
Apart from me being picky in the comment, I thought I could as well help with this one as well. I think you need to search for the culprit somewhere else. I created a new project and a view controller with this snippet:
#import "VC1.h"
#implementation VC1
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self performSelector:#selector(presentModal) withObject:nil afterDelay:1.0];
}
- (void)presentModal {
static int colorChooser = 0;
VC1 *vc1 = [[[VC1 alloc] init] autorelease];
switch (colorChooser%2) {
case 0:
vc1.view.backgroundColor = [UIColor whiteColor];
break;
default:
vc1.view.backgroundColor = [UIColor blackColor];
break;
}
colorChooser++;
[self presentModalViewController:vc1 animated:YES];
}
#end
And it works flawlessly after being pushed on the navigation controller. It is recursively alternating between black and white views, tested both in the sim and on a 3G device.
Maybe you are doing some other view transitions due to some notifications or other asynchronic means? Either way you would need to share more of your code for anyone to tell where the problem is.
Our preferred solution is to use -[UIViewController presentViewController:animated:completion:] and do whatever the next action is (eg presenting another VC) in the completion block.
For example:
[self presentViewController:yourViewController animated:YES completion:^{
[yourViewController presentMyModal];
}];
This method was introduced in iOS 5.0.

Code data issue after upgrade to XCode + iOS 4.2

NSEntityDescription *entity = [NSEntityDescription entityForName:#"Thread" inManagedObjectContext:managedObjectContext];
That line doesn't seem to work anymore (I'm pretty sure its that line).
I can't seem to work out whats the problem. The application worked perfectly on Xcode with iOS 4.1 and now crashes with this error in the console:
2010-12-07 17:12:27.552 SMSApp[9222:207] +[ persistentStoreCoordinator]: unrecognized selector sent to class 0x5b14580
2010-12-07 17:12:27.553 SMSApp[9222:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[ persistentStoreCoordinator]: unrecognized selector sent to class 0x5b14580'
*** Call stack at first throw:
(
0 CoreFoundation 0x01547be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0169c5c2 objc_exception_throw + 47
2 CoreFoundation 0x015497bb +[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x014b9366 ___forwarding___ + 966
4 CoreFoundation 0x014b8f22 _CF_forwarding_prep_0 + 50
5 CoreData 0x00e6f3ca +[NSEntityDescription entityForName:inManagedObjectContext:] + 42
6 SMSApp 0x000046b9 -[MessagesRootViewController reloadMessages:] + 146
7 SMSApp 0x00004a09 -[MessagesRootViewController viewDidLoad] + 85
8 UIKit 0x0052265e -[UIViewController view] + 179
9 UIKit 0x00520a57 -[UIViewController contentScrollView] + 42
10 UIKit 0x00531201 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
11 UIKit 0x0052f831 -[UINavigationController _layoutViewController:] + 43
12 UIKit 0x00530b4c -[UINavigationController _startTransition:fromViewController:toViewController:] + 524
13 UIKit 0x0052b606 -[UINavigationController _startDeferredTransitionIfNeeded] + 266
14 UIKit 0x00643e01 -[UILayoutContainerView layoutSubviews] + 226
15 QuartzCore 0x010b4451 -[CALayer layoutSublayers] + 181
16 QuartzCore 0x010b417c CALayerLayoutIfNeeded + 220
17 QuartzCore 0x010ad37c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
18 QuartzCore 0x010ad0d0 _ZN2CA11Transaction6commitEv + 292
19 UIKit 0x0047719f -[UIApplication _reportAppLaunchFinished] + 39
20 UIKit 0x00477659 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 690
21 UIKit 0x00481db2 -[UIApplication handleEvent:withNewEvent:] + 1533
22 UIKit 0x0047a202 -[UIApplication sendEvent:] + 71
23 UIKit 0x0047f732 _UIApplicationHandleEvent + 7576
24 GraphicsServices 0x01b2ca36 PurpleEventCallback + 1550
25 CoreFoundation 0x01529064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
26 CoreFoundation 0x014896f7 __CFRunLoopDoSource1 + 215
27 CoreFoundation 0x01486983 __CFRunLoopRun + 979
28 CoreFoundation 0x01486240 CFRunLoopRunSpecific + 208
29 CoreFoundation 0x01486161 CFRunLoopRunInMode + 97
30 UIKit 0x00476fa8 -[UIApplication _run] + 636
31 UIKit 0x0048342e UIApplicationMain + 1160
32 SMSApp 0x000025c4 main + 102
33 SMSApp 0x00002555 start + 53
)
terminate called after throwing an instance of 'NSException'
Any idea where this error is coming from or what is causing it?
Just to let you know as well, upgrading to XCode with iOS 4.2 caused some of the files to be deleted from my project. I don't know why this was, whether it was because they were linked files and not actually in the folder I dunno.
Any ideas?
Thanks
// EDIT
This method is in the AppDelegate:
- (NSManagedObjectContext *)managedObjectContext {
if (managedObjectContext_ != nil) {
return managedObjectContext_;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
managedObjectContext_ = [[NSManagedObjectContext alloc] init];
[managedObjectContext_ setPersistentStoreCoordinator:coordinator];
}
return managedObjectContext_;
}
// EDIT AGAIN
- (void)reloadMessages:(NSNotification *)notification {
NSLog(#"RECIEVED NEW MESSAGES TO MessagesRootViewController");
NSLog(#"%#",managedObjectContext);
// we need to get the threads from the database...
NSFetchRequest *theReq = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Thread" inManagedObjectContext:self.managedObjectContext];
[theReq setEntity:entity];
threads = [NSArray arrayWithArray:[managedObjectContext executeFetchRequest:theReq error:nil]];
[self.tableView performSelectorOnMainThread:#selector(reloadData) withObject:nil waitUntilDone:NO];
if(notification != nil){ // if its been caused by a notification
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"New Message" message:#"A new message has been received" delegate:nil cancelButtonTitle:#"Thanks" otherButtonTitles:nil];
[alert performSelectorOnMainThread:#selector(show) withObject:nil waitUntilDone:NO];
[alert release];
}
}
// EDIT 3
If I put this code in the applicationDidFinishLoading of my app delegate it works fine!
NSFetchRequest *theReq = [[NSFetchRequest alloc] init];
NSEntityDescription *theEntity = [NSEntityDescription entityForName:#"Thread" inManagedObjectContext:self.managedObjectContext];
[theReq setEntity:theEntity];
NSArray *theThreads = [NSArray arrayWithArray:[self.managedObjectContext executeFetchRequest:theReq error:nil]];
After having a quick look at your code I think I found a couple of parts that needed attention. I'll try and break them down below:
SMSAppAppDelegate
1) Notice that in your interface file, you declare your CoreData variables with an underscore at the end of the variable name. Then you create properties for each of the ivar without the underscore. That is all fine as long as you #synthesize them making the correct assignment, which seems to be missing from your implementation:
#synthesize managedObjectContext=managedObjectContext_;
#synthesize managedObjectModel=managedObjectModel_;
#synthesize persistentStoreCoordinator=persistentStoreCoordinator_;
DownloadContacts
1) In this class you are calling the managedObjectContext directly through the variable. I wouldn't recommend that but this is not your actual problem. Notice that you release the managedObjectContext on dealloc even though you have no ownership of it!
2) What I would do in this case is declare a property for the context and always access it via the property. Also if you rename your instance variable to include an underscore at the end you are minimising your chances of accessing it directly (i.e. without using self.) and it will make it easier for you to find where in this class you are actually doing that (there are a couple of places from memory).
So in your interface file, rename managedObjectContext ivar and declare a property:
NSManagedObjectContext *managedObjectContext_;
...
#property (nonatomic, retain) NSManagedObjectContext managedObjectContext;
And don't forget to make the assignment on #sythesize and release on dealloc, since you are using a retain property:
#synthesize managedObjectContext=managedObjectContext_;
...
[managedObjectContext_ release];
Then if you try and compile you will get two or three errors of unrecognised instance variable which is where you have to go and change it to self.managedObjectContext
MessagesRootViewController
And finally I'd recommend you go through the same process in your MessagesRootViewController but this one should still work fine as is!
See how you go and let me know if any of the above is not clear!
Cheers,
Rog
I'm assuming you're doing something like:
[ClassName persistentStoreCoordinator]
Make sure ClassName is defined and has the persistentStoreCoordinator class method. Perhaps the file that did these things got deleted?
Matt
Your database might be corrupted, try resetting the iOS simulator
by clicking on iOS Simulator>Reset contents and settings.
Edit:
It looks like you're trying to call a selector that doesn't exist. Try figuring out which files were deleted, as it seems like you have a method that is called that can't be found at runtime. Did your core data classes get erased, maybe?

NSObject's 'description' method giving parentheses as output?

So, I'm debugging an app I'm building and using the description method to help me find the problem. But instead of giving me the app as a string it is printing out parentheses instead. Please help!
Here's the code:
- (void)viewDidLoad {
[super viewDidLoad];
reminders = [[NSMutableArray alloc] init];
currentTitle = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
currentSummary = [[
NSMutableString alloc] init];
currentLink = [[NSMutableString alloc] init];
NSLog(#"IT'S HERE %#", [reminders description]);}
...
and the error:
[Session started at 2010-10-04 22:15:16 -0400.]
2010-10-04 22:15:17.434 Reminders[5824:207] ******* Accessibility Status Changed: On
2010-10-04 22:15:17.464 Reminders[5824:207] ********** Loading AX for: com.yourcompany.Reminders ************
2010-10-04 22:15:17.506 Reminders[5824:207] IT'S HERE (
)
2010-10-04 22:15:17.510 Reminders[5824:207] Hello
2010-10-04 22:15:17.512 Reminders[5824:207] (
)
2010-10-04 22:15:17.514 Reminders[5824:207] PVC: <UITableView: 0x602d600; frame = (0 20; 320 460); clipsToBounds = YES; opaque = NO; autoresize = W+H; layer = <CALayer: 0x5f3f3b0>; contentOffset: {0, 0}>
2010-10-04 22:15:17.514 Reminders[5824:207] It's here
2010-10-04 22:15:17.515 Reminders[5824:207] Loaded
2010-10-04 22:15:17.520 Reminders[5824:207] -[__NSCFArray name]: unrecognized selector sent to instance 0x6a4b640
2010-10-04 22:15:17.523 Reminders[5824:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray name]: unrecognized selector sent to instance 0x6a4b640'
*** Call stack at first throw:
(
0 CoreFoundation 0x0248bb99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x025db40e objc_exception_throw + 47
2 CoreFoundation 0x0248d6ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x023fd2b6 ___forwarding___ + 966
4 CoreFoundation 0x023fce72 _CF_forwarding_prep_0 + 50
5 Reminders 0x00003aa9 -[RootViewController tableView:cellForRowAtIndexPath:] + 300
6 UIKit 0x00090d6f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 619
7 UIKit 0x00086e02 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
8 UIKit 0x0009b774 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
9 UIKit 0x000937ec -[UITableView layoutSubviews] + 242
10 QuartzCore 0x03f60481 -[CALayer layoutSublayers] + 177
11 QuartzCore 0x03f601b1 CALayerLayoutIfNeeded + 220
12 QuartzCore 0x03f592e0 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 302
13 QuartzCore 0x03f59040 _ZN2CA11Transaction6commitEv + 292
14 UIKit 0x0002204e -[UIApplication _reportAppLaunchFinished] + 39
15 UIKit 0x00022477 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 545
16 UIKit 0x0002c3ec -[UIApplication handleEvent:withNewEvent:] + 1958
17 UIKit 0x00024b3c -[UIApplication sendEvent:] + 71
18 UIKit 0x000299bf _UIApplicationHandleEvent + 7672
19 GraphicsServices 0x026fa822 PurpleEventCallback + 1550
20 CoreFoundation 0x0246cff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
21 CoreFoundation 0x023cd807 __CFRunLoopDoSource1 + 215
22 CoreFoundation 0x023caa93 __CFRunLoopRun + 979
23 CoreFoundation 0x023ca350 CFRunLoopRunSpecific + 208
24 CoreFoundation 0x023ca271 CFRunLoopRunInMode + 97
25 UIKit 0x00021c6d -[UIApplication _run] + 625
26 UIKit 0x0002daf2 UIApplicationMain + 1160
27 Reminders 0x00002078 main + 102
28 Reminders 0x00002009 start + 53
)
terminate called after throwing an instance of 'NSException'
Here's the method that you asked for fluchtpunkt
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
Reminder *theReminder = [reminders objectAtIndex:indexPath.row];
cell.textLabel.text = theReminder.name;
return cell;
}
those parentheses are the output I would expect if I NSLog an empty array.
This is absolutely correct.
the exception is raised because you try to call a name method on an NS(Mutable)Array. And arrays don't respond to name.
To find the cause of this Exception post the code of this method in your RootViewController
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

How to ensure that UIImage is never released?

I grabbed the crash log from the iPhone:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000c
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x30011940 objc_msgSend + 20
1 CoreFoundation 0x30235f1e CFRelease + 98
2 UIKit 0x308f4974 -[UIImage dealloc] + 36
3 CoreFoundation 0x30236b72 -[NSObject release] + 28
4 UIKit 0x30a00298 FlushNamedImage + 64
5 CoreFoundation 0x30250a20 CFDictionaryApplyFunction + 124
6 UIKit 0x30a0019c _UISharedImageFlushAll + 196
7 UIKit 0x30a00730 +[UIImage(UIImageInternal) _flushCacheOnMemoryWarning:] + 8
8 Foundation 0x3054dc7a _nsnote_callback + 178
9 CoreFoundation 0x3024ea52 _CFXNotificationPostNotification + 298
10 Foundation 0x3054b854 -[NSNotificationCenter postNotificationName:object:userInfo:] + 64
11 Foundation 0x3054dbba -[NSNotificationCenter postNotificationName:object:] + 14
12 UIKit 0x30a00708 -[UIApplication _performMemoryWarning] + 60
13 UIKit 0x30a006a0 -[UIApplication _receivedMemoryNotification] + 128
14 UIKit 0x30a005d0 _memoryStatusChanged + 56
15 CoreFoundation 0x30217410 __CFNotificationCenterDarwinCallBack + 20
16 CoreFoundation 0x3020d0aa __CFMachPortPerform + 72
17 CoreFoundation 0x30254a70 CFRunLoopRunSpecific + 2296
18 CoreFoundation 0x30254164 CFRunLoopRunInMode + 44
19 GraphicsServices 0x3204529c GSEventRunModal + 188
20 UIKit 0x308f0374 -[UIApplication _run] + 552
21 UIKit 0x308eea8c UIApplicationMain + 960
...
...
From my previous question, Can somebody give me a hand about this stacktrace in iPhone app?, I have changed my codes mainly around UIImage part. I now use [[UIImage alloc] initWithContentsOfFile ... ]. No more [UIImage imageNamed: ... ] or the like. The portion is below.
//this is a method of a subclass of UIImageView.
- (void) reviewImage: (bool) review{
NSString* st;
if (review){
NSString* origin = [NSString stringWithString: [[ReviewCardManager getInstance] getCardImageString:chosenIndex]];
NSString* stt = [origin substringToIndex: [origin length]-4];
st = [[NSString alloc] initWithString: stt];
if (myImageFlipped == nil)
myImageFlipped = [[UIImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:st ofType:#"png"]];
[self setImage:myImageFlipped];
if (notRotated){
self.transform = CGAffineTransformRotate(self.transform, [MyMath radf:rotate]);
notRotated = false;
}
}else{
st = [[NSString alloc] initWithFormat:#"sc%d", chosenNumber];
if (myImage == nil)
myImage = [[UIImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:st ofType:#"png"]];
[self setImage:myImage];
if (notRotated){
self.transform = CGAffineTransformRotate(self.transform, [MyMath radf:rotate]);
notRotated = false;
}
}
[st release];
}
I also have the UIImage already retained in the property.
#property (nonatomic, retain) UIImage* myImage, *myImageFlipped;
Memory Leaks have also been taken cared of. These variables are release in dealloc method.
I thought that I have successfully killed the bug, but it seems that I still have a rare occuring bug problem.
Based on the crash log, my application yells out "performMemoryWarning". I am just "alloc"-ing 13 .png images with the size 156 x 272. I'm confused. Those images shouldn't take that much memory to the point that it exceeds iPhone's RAM. Or is there something I am overlooking? Please advise.
To help you with memory issues and UIImages, you might want to use the imageNamed convience method of UIImage, from the docs:
This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object.
Alternatively, you might want to go this route if you still run into memory issues after switching to UIImage imageNamed, because there are some downsides to using the convinience method.
The problem is solved. I forgot to change UIImage at one place. Now, all UIImages are truly "alloc", no more autorelease.
FYI, if you are using [UIImage imageNamed: ... ], use "Simulate Memory Warning" on iPhone Simulator to see whether you are having a problem with it when the real device is low on memory.