CCLabelBMFont crashing due to a missing image message - objective-c

I'm getting an exception saying that the image cannot be nil on this line:
CCLabelBMFont *label = [CCLabelBMFont labelWithString:#"5" fntFile:#"weaponnumbers.fnt"];
What am I doing wrong? Am I supposed to specify the PNG somewhere different? I have it at the root of the project.
-(CCTexture2D*) addImage: (NSString*) path
{
NSAssert(path != nil, #"TextureCache: fileimage MUST not be nill");

Is weaponnumbers.fnt included in your target? E.g. is it compiled into the project?
Also, I think it's unlikely you're getting an exception here - you're probably getting an exception somewhere inside one of the calls made by this call. Try breakpointing the line before, and using the "Step In" breakpoint tool to step through the call stack and find the true nature of the exception.
I find Cocos2D exceptions to be pretty self-explanatory, when you can eventually get down to the right level of where the exception is actually being thrown.

A delete add and clean fixed it.
NSString stringWithContentsOfFile failing with what seems to be the wrong error code

Related

[__NSArrayM insertObject:atIndex:]: object cannot be nil raises even after checking nil

In my cocoa application, i am uploading files to my server. And i have status bar to display the current status of file uploads. When i click on the status bar, it will show the status of current uploading file. For displaying the current status, i am adding retrieved value as objects to array.
Here i given the code for adding objects to array.
if(temp1 != Nil)
{
[printComplete addObject:temp1];
}
Same type of code has been used in my code at multiple points. But sometime i am getting the below error even after checking the nil:
-[__NSArrayM insertObject:atIndex:]: object cannot be nil
I can't get this error when i run this code from Xcode / at debugging stage. It occurs rarely when i run this as app. Can anyone provide the solution to resolve this issue.
Ok, so my original suggestion was to try the following, as OP was is testing for equality with Nil instead of nil:
if (temp1) {
[printComplete addObject:temp1];
}
Check out NSHiptser's take on nil/Nil.
However, it turns out that they are actually defined as the same thing, so this wouldn't be the source of the problem.
I would still recommend (stylistically) using each for their intended use.
Here's another interesting answer on the subject: https://stackoverflow.com/a/1843034/1716763
I'll leave this answer here, unless people think it isn't necessary.

Weird LLDB error in Xcode 4.5: Internal error [IRForTarget]

When putting breakpoint in some files, for example: Just newly created ViewController and putting breakpoint on viewDidLoad method I get strange LLDB error
Internal error [IRForTarget]: Couldn't rewrite external variable _ZZ53
[EPGViewController($__lldb_category) $__lldb_expr:]E19$__lldb_expr_result
I tried googling for this error - can't find anything useful. Cleaning cache, restarting doesn't help.
Once more - this error I get not on all files. And I can't figure out why.
Thx for any help or tips!
Also, when I try to po some variable I get
(lldb) po self.title
error: Couldn't materialize struct: Structure hasn't been laid out yet
Internal error [IRForTarget]: Couldn't rewrite external variable _ZZ58-
[EventsEPGViewController($__lldb_category) $__lldb_expr:]E19$__lldb_expr_result
I ran into this error as well and spent a lot of time debugging it fruitlessly. It seems to be related to the breakpoint itself: I noticed that if I deactivated the breakpoint the error doesn't appear.
You might be able to just move the breakpoint to another line to suppress. This isn't the first clang bug I've run into, on XCode 4.3 'po' wouldn't even output variables reliably.
Change your designated debugger for that project from lldb to gdb and you're good.

Trying to trace an error in xcode

When I start up my application I get the error detailed below. If I continue the application everything seems to be working fine. The error is raised between the calls to applicationWillFinishLaunching and applicationDidFinishLaunching.
I suspect the eror is getting generated when the xib is being loaded, however I can see nothing wrong with the xib and how it is connected up. Can anyone give me some tips on how I can trace back to find the source of the error?
Thanks,
2012-08-21 11:31:55.293 ConjugationViewer[32508:707] *** Assertion failure in -[NSTextFieldCell _objectValue:forString:errorDescription:], /SourceCache/AppKit/AppKit-1138.47/AppKit.subproj/NSCell.m:1564
2012-08-21 11:31:55.303 ConjugationViewer[32508:707] Ignoring exception raised in __-[NSPersistentUIManager restoreAllPersistentStateWithTalagentWindows:registeringAsReadyWhenDone:completionHandler:]_block_invoke_3: Invalid parameter not satisfying: aString != nil
I had same problem.
In my case I had set
[NSTextField setStringValue:nil] By mistake.
You can trace the problem in your code using crash stack log.
The log shows function call as stack start from bottom. You can search the last call of your function after which cocoa functions get called. You can say problem present at the same function.

NSArray: Why is SIGABRT sent instead of an 'index out of bounds' kind of error?

Ok. So I had this extremely weird SIGABRT error on a complex Objective-C iOS program that I'm working on, and after one day of tracking I found the culprit.
Let's say we have the following code:
NSArray *a = [NSArray arrayWithObjects:#"a", #"b", #"c", nil];
NSLog(#"tada: %#", [a objectAtIndex:-1]);
Why the hell will this terminate the program with Program received signal: SIGABRT and the debugger not even pointing to my code (but rather in some assembly part) instead of a nicer 'index out of bounds' and 'hey, this line of code here be wrong' error?
I thought I messed up the project config, so I reproduced this on a brand new project: same result.
Is there a way to configure XCode to be more nice and indicate this kind of errors in a more human understandable way ?
As the documentation says:
If index is beyond the end of the array (that is, if index is greater
than or equal to the value returned by count), an NSRangeException is
raised
And the default action, when no exception handler is defined, is to... well... you can see what the default behaviour is.
You can use #try/#catch to trap the exception, but that's not really Objective-C-ish. You know how many elements are in the array; there's no real need for you to be accessing elements that don't exist.
Exceptions like this normally have a stack trace, so you can go back to the line of code causing the error. (It might be worth switching between LLDB and GDB if it's not working correctly. LLDB is faster and smaller but not completely reliable.(
You should see something along the lines of "index of out range" if you look in the console log in Xcode. SIGABRT is the result of an assertion being fired. Sometimes you have to hit "Continue" after the crash in order to get the message to print.
The debugger tells you where the crash actually happened. It doesn't know what the original cause was. If the debugger leaves you looking at the assembler, just move up the stack until you reach your code.

How can I work around "Xcode could not locate source file"

I'm working with the ID3 framework in Xcode (which has since disappeared off the face of the web - including google cache!).
I'm testing out an import mp3 feature which allows them to edit the tags as they import them. One of the test cases is a corrupt or invalid mp3 with no proper id3 header. The problem I'm having is that when updating the tags of the invalid mp3 (updateFile:), the ID3 framework attempts to use id3V1Tag.m (I assume it falls back to this if it can't find the v2 tag) and this is where I get the Xcode error (whilst running the program, not building):
Xcode could not locate source file: id3V1Tag.m (line: 299)
Even in a release build this crashes the program, so it's not something I can really ignore.
I've tried putting a try/catch block around it but it's not treated as an exception so doesn't get caught. The function to load the tag data for the file returns a BOOL but it appears this only returns false if the given file doesn't exist, so this doesn't help either.
Current code:
[tagData release];
tagData = [[TagAPI alloc] initWithGenreList:nil];
tagsLoaded = [tagData examineFile:exportPath];
if(tagsLoaded) {
[tagData setTitle:title];
[tagData setArtist:artist];
[tagData setComments:comments];
#try {
[tagData updateFile];
}
#catch (id e){
NSLog(#"h");
}
}
The error you're getting is that Xcode is trying to locate your source file id3V1Tag.m in order to show it during debugging. No code you write will affect this.
If you don't have the id3V1Tag.m source file in your framework distro, there's nothing you can do about this, and there's little to do but ignore it (other than seeing if you can avoid causing it to be requested, like not setting a breakpoint in it, not stepping into it, and not crashing in it).
If you do have it, and are building it, then perhaps you're not building with the right debug information, so you'll have to tell us more about your build setup.
So the problem you're having is that your program is crashing when you attempt to compile id3V1Tag.m or while running the program. I'm a bit confused on that.
If its crashing while running maybe this is an issues with a code file missing from a library? How are you reading the ID3 tag information exactly? Is it through your own code or through a 3rd party library/class.