0
votes

I am working on my first iPhone app it has been running well so far, but suddenly it started crashing and I kept getting this error:

2012-08-13 08:39:50.000 OGLGame[36085:10a03] -[NSCFString setFrame:]: unrecognized selector sent to instance 0x7368300 2012-08-13 08:39:50.031 OGLGame[36085:10a03] ( 0 CoreFoundation
0x0166203e __exceptionPreprocess + 206 1 libobjc.A.dylib
0x01c7fcd6 objc_exception_throw + 44 2 CoreFoundation
0x01663cbd -[NSObject doesNotRecognizeSelector:] + 253 3
CoreFoundation 0x015c8ed0 __forwarding
+ 432 4 CoreFoundation 0x015c8cb2 _CF_forwarding_prep_0 + 50 5 OGLGame 0x00004673 -[EAGLView setupScore] + 355 6 OGLGame
0x0000335b -[EAGLView initGame] + 299 7 OGLGame
0x00003217 -[EAGLView initWithCoder:] + 1047 8 UIKit
0x00a48135 -[UIClassSwapper initWithCoder:] + 243 9 UIKit
0x00b47c6e UINibDecoderDecodeObjectForValue + 2276 10 UIKit
0x00b47383 -[UINibDecoder decodeObjectForKey:] + 117 11 UIKit
0x00a47cad -[UIRuntimeConnection initWithCoder:] + 187 12 UIKit
0x00b47c6e UINibDecoderDecodeObjectForValue + 2276 13 UIKit
0x00b4767b UINibDecoderDecodeObjectForValue + 753 14 UIKit
0x00b47383 -[UINibDecoder decodeObjectForKey:] + 117 15 UIKit
0x00a47105 -[UINib instantiateWithOwner:options:] + 817 16 UIKit
0x00a48eb7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 157 17 UIKit
0x00825ce1 -[UIApplication _loadMainNibFileNamed:bundle:] + 58 18 UIKit 0x00825ff8 -[UIApplication _loadMainInterfaceFile] + 225 19 UIKit 0x0082517f -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 279 20 UIKit 0x00834183 -[UIApplication handleEvent:withNewEvent:] + 1027 21 UIKit 0x00834c38 -[UIApplication sendEvent:] + 68 22 UIKit
0x00828634 _UIApplicationHandleEvent + 8196 23 GraphicsServices
0x03af7ef5 PurpleEventCallback + 1274 24 CoreFoundation
0x01636195 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 53 25 CoreFoundation 0x0159aff2 __CFRunLoopDoSource1 + 146 26 CoreFoundation 0x015998da __CFRunLoopRun + 2218 27 CoreFoundation
0x01598d84 CFRunLoopRunSpecific + 212 28 CoreFoundation
0x01598c9b CFRunLoopRunInMode + 123 29 UIKit
0x00824c65 -[UIApplication _run] + 576 30 UIKit
0x00826626 UIApplicationMain + 1163 31 OGLGame
0x000029c4 main + 116 32 OGLGame
0x00002945 start + 53 33 ???
0x00000001 0x0 + 1 )

Here is the function that I believe is throwing the error:

-(void) setupScore{

scoreLabel = [NSString stringWithFormat:@"foo"];
scoreLabel.frame = CGRectMake(262, 250, 100, 40);
[scoreLabel setText: scoreString];

//normally you'll want a transparent background for your label
scoreLabel.backgroundColor = [UIColor clearColor]; 

//you can use non-standard fonts
[scoreLabel setFont:[UIFont fontWithName:@"TimesNewRoman" size: 1.0f]];

//change the label's text color
scoreLabel.textColor = [UIColor whiteColor];

//you can even create a drop shadow on your label text
/*myLabel.layer.shadowOpacity = 0.6;   
 myLabel.layer.shadowRadius = 0.0;
 myLabel.layer.shadowColor = [UIColor blackColor].CGColor;
 myLabel.layer.shadowOffset = CGSizeMake(1.0, 1.0);*/

//add it to your view
scoreLabel.transform = CGAffineTransformMakeRotation(89.53);
[self addSubview:scoreLabel];  }

-(void) resetScore { score = 0; scoreLabel.textColor = [UIColor blackColor]; [scoreLabel release]; }

-(void)drawScore{
[scoreLabel setText: scoreString]; }

Does anyone know how to fix this weird crash?

Let me know if you need more code, Thank You!

3
The issue is that your app has caused an exception to be thrown, and it doesn't catch the exception. You should tell the debugger to stop on exceptions (Objective-C and C++, but this one is Objective-C) and see which line of code is throwing the exception. That's where your error is.user1118321
Sorry I am new to all this, so how would I do that?iOS_Master
See this page for info on how to turn them on.user1118321
So I tried that, and it keeps pointing to the "int retVal" line of code and I don't know how to fix that.iOS_Master
Check out my answer on this question to get an NSLog of the offending line's call stack (then post it here): stackoverflow.com/questions/11462939/…Chris Trahey

3 Answers

1
votes

Based on the stack you posted, It is likely that there is a place inside [EAGLView setupScore] where you are assigning a variable to be something (likely an NSString) with just alloc, and not assigning the return of it's init method to the same var.

// this is WRONG!!
NSString *aString = [NSString alloc];
[aString initWithFormat:@"foo"];

// this is correct
NSString *aString = [[NSString alloc] initWithFormat:@"foo"];

// even better
NSString *aString = [NSString stringWithFormat:@"foo"];
// (class methods named in this manner (start with name of class) 
// take care of alloc and init for you)

The reason is that init methods are allowed to return a completely different pointer than alloc returns, and this new pointer is valid, the old one is not. always nest your alloc/init calls this way.

edit

Based on some info you posted in a comment on another answer, it looks like the call [scoreLabel setText: scoreString]; inside -(void) setupScore is using an improperly retained NSString object via scoreString.

My guess is that the @property for that string is declared to be weak, or else you are not properly initializing it anywhere.

edit 2

You have some improper handling of the scoreLabel and scoreString variables. In one place, you are setting your scoreLabel property to be an NSString. You likely intend to do:

scoreString = [NSString stringWithFormat:@"foo"];

Then, you are assuming that scoreLabel exists, but in one of your other methods you explicitly release it. This means that you need to check here for it properly existing, and create a new one if needed.

0
votes

Your code is probably accessing invalid memory. This happens frequntly when an object is deallocated and used afterwards. You can turn on zombie detection to deterct these cases.

-1
votes

The stacktrace shows that you're using an own view, EAGLView, which calls a method setupScore during initialization. Line 340 here causes the crash.

How does this method look like?