NSCFArray beyond bounds

  • Im getting an NSCFArray beyond bounds error in the console a lot from
    my app, im not sure how to find culprit. Is there any place i can put
    a break point that will only break when that message is output to the
    console? I tried 'NSLog' but that only seems to give me a 5 or 6
    frame stack. This seems to tell me that my problem is going on in
    another thread than the main thread. I also tried 'objectAtIndex' but
    that message is sent much too often. Please help!

    here's the error message:
    *** -[NSCFArray objectAtIndex:]: index (17) beyond bounds (17)

    thanks

    Alex
  • Try -[NSException raise]

    Ack, at 12/29/06, Alexander Cohen said:

    > Im getting an NSCFArray beyond bounds error in the console a lot
    > from my app, im not sure how to find culprit. Is there any place i
    > can put a break point that will only break when that message is
    > output to the console? I tried 'NSLog' but that only seems to give
    > me a 5 or 6 frame stack. This seems to tell me that my problem is
    > going on in another thread than the main thread. I also tried
    > 'objectAtIndex' but that message is sent much too often. Please help!
    >
    > here's the error message:
    > *** -[NSCFArray objectAtIndex:]: index (17) beyond bounds (17)

    --

    Sincerely,
    Rosyna Keller
    Technical Support/Carbon troll/Always needs a hug

    Unsanity: Unsane Tools for Insanely Great People

    It's either this, or imagining Phil Schiller in a thong.
  • I've had this happen to me a lot as well. The easiest way is to look
    for calls to objectAtIndex that doesn't use a constant. For example: a
    loop that calls objectAtIndex using the iteration number. It may also
    be that you're trying to access an object that has been removed from
    the array and you didn't realize.

    As a general rule it is a good idea to have some error checking when
    calling objectAtIndex.

    if ([array count] > index)
    {
      object = [array objectAtIndex: index];
    }
    else
    {
      NSLog(@"Bummer, we've messed up somehow. The array is too short,
    index (%i) is out of bounds", index);
    }

    Good luck hunting the bug down.
    Peace, Alan

    --
    // Quotes from yours truly -------------------------
    "You don't forget, you just don't remember."
    "Maturity resides in the mind."
    "Silence is the Universe's greatest gift."
    "When the World realizes that religion really is unnecessary, then it
    shall evolve."
  • Alexander Cohen (<alexcohen...>) on 2006-12-29 10:48 said:

    > Im getting an NSCFArray beyond bounds error in the console a lot from
    > my app, im not sure how to find culprit. Is there any place i can put
    > a break point that will only break when that message is output to the
    > console? I tried 'NSLog' but that only seems to give me a 5 or 6
    > frame stack. This seems to tell me that my problem is going on in
    > another thread than the main thread. I also tried 'objectAtIndex' but
    > that message is sent much too often. Please help!

    Maybe this would help:
    <http://developer.apple.com/technotes/tn2004/tn2124.html#SECCF>

    "The Core Foundation framework also has a debug variant that offers
    extensive debugging assistance. For example, the non-debug variant of
    Core Foundation does not check the validity of parameters that you pass
    to its routines, whereas the debug variant includes full parameter checking."

    Sean

    --
    "None are more hopelessly enslaved than those who falsely believe they
    are free." - Goethe
previous month december 2006 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Go to today