Debugging app... It keeps crashing!

Discussion in 'iOS Programming' started by noahgolm, Aug 24, 2010.

  1. macrumors member

    Joined:
    Aug 18, 2010
    #1
    I'm debugging a simple app (just a beginner one to get comfortable with some basic movement/animation) and I ran across a big bug. The app crashes whenever it's launched! I know the error, exec_bad_access, refers to memory problems, but I don't know where the problem lies! There are two areas the debugger points out. There is
    Code:
    #import "BallAppDelegate.h"
    #import "BallViewController.h"
    
    @implementation BallAppDelegate
    
    @synthesize window;
    @synthesize viewController;
    
    
    #pragma mark -
    #pragma mark Application lifecycle
    
    - (void)applicationDidFinishLaunching:(UIApplication *)application{
    	
    	[I][window addSubview:[viewController view]];[/I]
    	[window makeKeyAndVisible];
    }
    
    - (void)applicationWillResignActive:(UIApplication *)application {
        /*
         Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
         Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
         */
    }
    
    
    - (void)applicationDidEnterBackground:(UIApplication *)application {
        /*
         Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
         If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
         */
    }
    
    
    - (void)applicationWillEnterForeground:(UIApplication *)application {
        /*
         Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
         */
    }
    
    
    - (void)applicationDidBecomeActive:(UIApplication *)application {
        /*
         Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
         */
    }
    
    
    - (void)applicationWillTerminate:(UIApplication *)application {
        /*
         Called when the application is about to terminate.
         See also applicationDidEnterBackground:.
         */
    }
    
    
    #pragma mark -
    #pragma mark Memory management
    
    - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
        /*
         Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
         */
    }
    
    
    - (void)dealloc {
        [viewController release];
        [window release];
        [super dealloc];
    }
    
    
    @end
    
    where the italicized is selected, and
    Code:
    #import <UIKit/UIKit.h>
    
    int main(int argc, char *argv[]) {
        
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        [I]int retVal = UIApplicationMain(argc, argv, nil, nil);[/I]
        [pool release];
        return retVal;
    }
    
    where the problem is also italicized. Thank you!
     
  2. macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #2
    Viewcontroller is never allocced from what I see.


    Something like:

    BallViewController *viewController = [[BallViewController alloc] initFromNib.....
     
  3. thread starter macrumors member

    Joined:
    Aug 18, 2010
    #3
    Where would I put that in the code? The top one is the AppDelegate.m.
     
  4. macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #4
    Look at the names of the methods in the "Application lifecycle" section. If it helps, add NSLog() statements to each method in order to better understand their usage. Hope that helps!
     
  5. thread starter macrumors member

    Joined:
    Aug 18, 2010
    #5
    Agh! Still the same problem. Debugger shows the same problem, (the italicized one from the orginial code) too. In the area
    Code:
    - (void)applicationDidFinishLaunching:(UIApplication *)application{
    	
    	[window addSubview:[viewController view]];
    	[window makeKeyAndVisible];
    }
    
    I added this above the [window addSubview] line:
    Code:
    viewController =  [[BallViewController alloc] init];
    
    It's still is the same!
     
  6. macrumors 603

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #6
    Does your BallViewController have a retained view? And, if so, what is that view initialized to?
     
  7. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #7
    I assume you have a nib where the view and view controller are created. That's how this is usually done. You don't need to allocate something that is already allocated in your nib.

    What is the crash log? How do you expect help without showing the crash log? What does it say in the debugger console?
     
  8. thread starter macrumors member

    Joined:
    Aug 18, 2010
    #8
    Sorry, here's what the debugger console shows:
    Code:
    [Session started at 2010-08-25 18:31:46 -0400.]
    GNU gdb 6.3.50-20050815 (Apple version gdb-1469) (Wed May  5 04:36:56 UTC 2010)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
    Attaching to process 412.
    2010-08-25 18:31:48.432 Ball[412:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "BallViewController" nib but the view outlet was not set.'
    *** Call stack at first throw:
    (
    	0   CoreFoundation                      0x0238c919 __exceptionPreprocess + 185
    	1   libobjc.A.dylib                     0x024da5de objc_exception_throw + 47
    	2   CoreFoundation                      0x02345078 +[NSException raise:format:arguments:] + 136
    	3   CoreFoundation                      0x02344fea +[NSException raise:format:] + 58
    	4   UIKit                               0x0035b09c -[UIViewController _loadViewFromNibNamed:bundle:] + 295
    	5   UIKit                               0x00358cd1 -[UIViewController loadView] + 120
    	6   UIKit                               0x00358bab -[UIViewController view] + 56
    	7   Ball                                0x0000200d -[BallAppDelegate applicationDidFinishLaunching:] + 146
    	8   UIKit                               0x002b159c -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1252
    	9   UIKit                               0x002b39a1 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 346
    	10  UIKit                               0x002bd452 -[UIApplication handleEvent:withNewEvent:] + 1958
    	11  UIKit                               0x002b6074 -[UIApplication sendEvent:] + 71
    	12  UIKit                               0x002baac4 _UIApplicationHandleEvent + 7495
    	13  GraphicsServices                    0x02bf2afa PurpleEventCallback + 1578
    	14  CoreFoundation                      0x0236ddc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    	15  CoreFoundation                      0x022ce737 __CFRunLoopDoSource1 + 215
    	16  CoreFoundation                      0x022cb9c3 __CFRunLoopRun + 979
    	17  CoreFoundation                      0x022cb280 CFRunLoopRunSpecific + 208
    	18  CoreFoundation                      0x022cb1a1 CFRunLoopRunInMode + 97
    	19  UIKit                               0x002b3226 -[UIApplication _run] + 625
    	20  UIKit                               0x002beb58 UIApplicationMain + 1160
    	21  Ball                                0x00001f58 main + 102
    	22  Ball                                0x00001ee9 start + 53
    )
    terminate called after throwing an instance of 'NSException'
    
     
  9. macrumors 6502

    NickFalk

    Joined:
    Jun 9, 2004
    #9
    This sentence should give you fairly strong hint:

    reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "BallViewController" nib but the view outlet was not set.'" ;)
     
  10. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #10
    Why would you say it's a bad access when it's not? The error you show is an assertion failure, which is SIGABRT.

    As suggested, connect the view outlet to your view controller in your nib.
     
  11. thread starter macrumors member

    Joined:
    Aug 18, 2010
    #11
    Thanks guys. Yeah, I feel like a bit of an idiot. But I loaded the nib and added the view. Now I know what to do with problems like this, though! Sorry for the trouble.
     

Share This Page