Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Game with Sprite Kit Game Loop and Texture Atlas Adding a Title Scene

Jason Meinzer
Jason Meinzer
3,679 Points

Terminating app due to uncaught exception error....

Hoping somebody can help me here, been stuck for 2+ hours. I think the error I'm getting may be due to fact I'm using Xcode 6.1, and this video appears to have been released far prior to the release of 6.1.

Anyways, I followed everything religiously up to the end of this "Adding a Title Scene" video, and after importing my "splash_1" image I run my app, just like in the video, but mine crashes and I get a "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[_NSPlaceholderData initWithContentsOfFile:options:error:]: nil file argument'" error in my console.

It looks like the break point is in the Supporting Files > "main.m" file, on the line of code that reads, "return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));"

There's a highlighted green error on that line that reads "Thread 1: signal SIGABRT"

So far in the course we haven't even touched the main.m file, but for reference the entire contents of mine are:

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

Can't figure this one out, been working for hours. Here's the entire copy/paste of the error in the console if it helps for reference:

2015-04-10 21:11:41.236 AstroCat[21290:743721] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[_NSPlaceholderData initWithContentsOfFile:options:error:]: nil file argument'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010b30ca75 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010afa5bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010b30c9ad +[NSException raise:format:] + 205
    3   Foundation                          0x0000000109450c25 -[NSData(NSData) initWithContentsOfFile:options:error:] + 95
    4   Foundation                          0x00000001094eaa15 +[NSData(NSData) dataWithContentsOfFile:options:error:] + 61
    5   AstroCat                            0x00000001093a3f76 +[SKScene(Unarchive) unarchiveFromFile:] + 182
    6   AstroCat                            0x00000001093a413e -[GameViewController viewDidLayoutSubviews] + 206
    7   UIKit                               0x00000001099611f6 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 572
    8   QuartzCore                          0x000000010dadcc58 -[CALayer layoutSublayers] + 150
    9   QuartzCore                          0x000000010dad187e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    10  QuartzCore                          0x000000010dad16ee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    11  QuartzCore                          0x000000010da3f36e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
    12  QuartzCore                          0x000000010da40482 _ZN2CA11Transaction6commitEv + 390
    13  UIKit                               0x00000001098e568d -[UIApplication _reportMainSceneUpdateFinished:] + 44
    14  UIKit                               0x00000001098e6375 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2684
    15  UIKit                               0x00000001098e4d35 -[UIApplication workspaceDidEndTransaction:] + 179
    16  FrontBoardServices                  0x000000010cc14243 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
    17  CoreFoundation                      0x000000010b241c7c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    18  CoreFoundation                      0x000000010b2379c5 __CFRunLoopDoBlocks + 341
    19  CoreFoundation                      0x000000010b237785 __CFRunLoopRun + 2389
    20  CoreFoundation                      0x000000010b236bc6 CFRunLoopRunSpecific + 470
    21  UIKit                               0x00000001098e47a2 -[UIApplication _run] + 413
    22  UIKit                               0x00000001098e7580 UIApplicationMain + 1282
    23  AstroCat                            0x00000001093a4933 main + 115
    24  libdyld.dylib                       0x000000010c5e4145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

I'd greatly appreciate any help here, thanks!!! Definitely stuck.

2 Answers

It is difficult to say, but have you got some orphan IBOutlets or IBActions? i.e. have you done a drag/drop into the code more than once to create these links and either deleted the code, or the GUI object?

If you have done that, you've got to find the link and delete it too. Otherwise, this will throw this type of error. Many other things will too, but that's a common one. It isn't to do with the Xcode version.

Have a think whether you've done that and locate the broken link and delete it.

Jason Meinzer
Jason Meinzer
3,679 Points

Thanks for your response, Steve. I am right on the same page as you - that was one of the first things I looked into. I actually just figured out the solution, after debugging for quite some time.

I changed the following code in my THViewController from:

THTitleScene * scene = [THTitleScene unarchiveFromFile:@"THTitleScene"]

To:

SKScene * scene = [THTitleScene sceneWithSize:skView.bounds.size];

And that fixed it!