My iPhone game crashed whilst on the device and I am attempting to understand what happened.
Every time a user exits the game screen it will send a message to the HomePageController (my top level controller) telling it to save the user data. This works fine all the time except for in this particular instance. The exception thrown seems to state that HomePageController did not recognize the saveUserData selector but I can’t see how that can happen as that function is definitely in that controller and it works the rest of the time.
Can anyone offer any advice?
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x3756a88f __exceptionPreprocess + 163
1 libobjc.A.dylib 0x35a70259 objc_exception_throw + 33
2 CoreFoundation 0x3756da9b -[NSObject doesNotRecognizeSelector:] + 175
3 CoreFoundation 0x3756c915 ___forwarding___ + 301
4 CoreFoundation 0x374c7650 _CF_forwarding_prep_0 + 48
5 P------k 0x0000ebe1 -[HomePageController saveUserData] (HomePageController.m:125)
6 P------k 0x00008a0b -[RootViewController viewDidAppear:] (RootViewController.m:102)
Line 125 in HomePageController.m:
- (void)saveUserData{
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
//10x10
{
NSMutableDictionary *dict = [[[NSMutableDictionary alloc] init] autorelease];
for (int i = 0; i < _puzzles10x10.count; i++){
LevelData *currentPuzzle = [_puzzles10x10 objectAtIndex:i];
/*(line 125)*/ [dict setObject:[currentPuzzle getPuzzleUserData] forKey:currentPuzzle.title];
}
[dict writeToFile:[documentsPath stringByAppendingPathComponent:@"userdata.dat"] atomically:YES];
}
// more here
}
If
currentPuzzledoesn’t recognize the selectorgetPuzzleUserDatathen the problem is one of these two:LevelDatadoes not define a methodgetPuzzleUserData.currentPuzzleis not an instance ofLevelDataSo check if the method is actually defined in the class
LevelDataand not inHomePageControllerand that when you add items to_puzzles10x10they are actually instances ofLevelData.To debug further, split your code into as many lines as possible (one instruction per line), add a lot of
NSLogcalls and see what happens: