crash between viewDidLoad and viewWillAppear...?

Discussion in 'iOS Development' started by cybohemia, May 30, 2009.

  1. cybohemia

    cybohemia New Member

    Joined:
    Jan 25, 2009
    Messages:
    49
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    My app seems to be crashing after it leaves viewDidLoad for a ViewController but before it enters viewWillAppear for the same controller.

    The error I get is: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)'

    I'm not sure how to use the debugger to figure out what's going on since the crash appears to be happening outside of the code I wrote. Does an error with NSCFArray indicate the sort of underlying problem?

    Any hints or suggestions would be greatly appreciated - thanks!
  2. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    Your app tries to access an object of an array that has no objects in it.
    You're saying that it happens outside of your code.. well just post your code if it's possible, or have a look yourself:
    Where do you use something like this?
    Code:
    [someArray objectAtIndex:aNumber]
    Check if this array is filled correctly before accessing it.
  3. cybohemia

    cybohemia New Member

    Joined:
    Jan 25, 2009
    Messages:
    49
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    Although I do use arrays in my app, the crash only happens after the camera is used to successfully save a picture from the image picker - it doesn't crash when the same image picker interface is used to save a picture from the album. That's one reason that leads me to think it's not my code - not in a straightforward way, anyway - since I don't do anything different for the camera that I do for the album.

    Also, the "index (0) beyond bounds (0)" makes it seem like an array isn't initialized but that I've stepped through the debugger and going from a safe part of the code to the crash, I don't encounter any arrays not properly defined.

    At one point in the debugging, I reach the end of the viewDidLoad() routine and I can't step any further so I choose "continue" and that's when things crash.

    The crash seems to occur in the nether world after the viewDidLoad but before the viewWillAppear. I'm not sure what to post, actually, since the app itself is rather big and unwieldy while the actual code in viewDidLoad and the routine that pops out of the previous view, in and of themselves, may not be very revealing.

    One thing I'm wondering: the ViewController that is doing the viewDidLoad (that crashes) only does it when the camera is used; it doesn't do it when the album is used. Way earlier in the app, the ViewController had already done its viewDidLoad so I'm guessing the camera cleared it out and it has to re-load, which may be doing some stuff with some array that is causing a problem...? I'm sort of wildly guessing here...but if it rings a bell with anyone...?
  4. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    This really sounds like it's a bug in the private methods that the system uses.
    But if it's true, many others would have reported similar problems... And I can't find anything on the net related to that problem.

    Maybe someone else can help you, my knowledge is very limited so I don't think I can help you any more.

    Please Register or Log in to view images

  5. cybohemia

    cybohemia New Member

    Joined:
    Jan 25, 2009
    Messages:
    49
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    I'm guessing it's like most biggish system-related bugs: diagnosing the symptoms is the toughest part. Once it's localized, it might end up being the sort of bug others have seen...hopefully what I'm seeing so far will trigger some folks who recognize similar behavior.

    Thanks for your help!
  6. Cyanidepoison

    Cyanidepoison Active Member

    Joined:
    Jan 18, 2008
    Messages:
    1,076
    Likes Received:
    2
    Uh... I'm gonna say there aren't any bugs in Foundation that'd you'd be able to find.


    It's your fault, just post some code.
  7. cybohemia

    cybohemia New Member

    Joined:
    Jan 25, 2009
    Messages:
    49
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    So I've found the line of code that seems to be causing the problem. The object crashing is a UIViewTable object and the operation that causes it to crash is:

    Code:
    int num = [self.model.wishes count] - 1;
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:num inSection:0];
    NSArray *nsa = [NSArray arrayWithObject:indexPath];
    [self.tableView insertRowsAtIndexPaths:nsa withRowAnimation:NO];
    
    This code works ok after the user has created the item to add and returns to the table view, ListViewController, from the AddViewController. However, if the user had used the camera in the AddViewController then it crashes. It doesn't crash if the user didn't use the camera or if the user chose something from the album when inside of AddViewController.

    I understand that, in the past, the camera has had a number of memory leaks that caused problems but I don't know if those are still around or if the problems would cause such side effects.

    I can't post the entire project as it is too massive. With memory leaks, isolating parts of the code may make the problem disappear since it could have something to do with heap allocation. In any case, I'll keep trying and let folks know if I get anywhere. In the meantime, any constructive insights greatly appreciated. Unconstructive flippant comments, well, less so - but some people...
  8. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    First of all, you have nothing there to check to see if your array even exists or has any objects in it. That could be a major source of fail. Also, withRowAnimation:NO is wrong. That message does not want a bool for input. Reread the docs to see what to out there.

    And no, we can't find your bug without seeing your code. But I will guarantee you the bug is in your code and not the frameworks. I use the photopicker quite extensively for both photo library and camera operations, so I know it works.

Share This Page