Results 1 to 4 of 4
  1. #1
    NSMutableArry and “EXC_BAD_ACCESS”

    Member Since
    Sep 11, 2009
    Posts
    1
    NSMutableArry and “EXC_BAD_ACCESS”
    Could somebody help me?

    I declared NSMutableArray in header file like this:
    TPEditGlyphView.h:

    @interface TPEditGlyphView : NSView
    {
    ...
    NSMutableArray * observedKnots;
    ....
    }

    Next I try to use one, but any access makes "EXC_BAD_ACCESS"..

    TPEditGlyphView.m:
    //only places where observedKnots appears
    .....
    -(void) awakeFromNib
    {
    .....
    observedKnots = [NSMutableArray arrayWithCapacity:0]; //CRASH, EXPLOSION...
    }

    -(void) observeValueForKeyPath: keyPath ofObject: object change: change context:context {
    if (context == TPKnotsSelectionDidChangedContext) {
    for (TPKnot *knot in observedKnots) { //CRASH, EXPLOSION...
    ....
    }
    observedKnots = [NSMutableArray arrayWithCapacity:0];
    for (TPKnot *knot in [knotsController selectedObjects]) {
    ....
    [observedKnots addObject: knot];
    ....
    }
    }
    ....

    Where could be bug?

  2. #2
    NSMutableArry and “EXC_BAD_ACCESS”
    xstep's Avatar
    Member Since
    Jun 25, 2005
    Location
    On the road
    Posts
    3,231
    Specs:
    2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
    Do you have the foundation kit imported, as in;

    Code:
    #import <Foundation/Foundation.h>
    I did try the observedKnots declaration with the assignment statement and it worked fine for me.
    CameraTime - Time lapse photography for novice and advanced users.

    When asking questions, post the version of your software. You'll receive better answers.

    Please post your results to the thread as it is good feedback.

  3. #3
    NSMutableArry and “EXC_BAD_ACCESS”

    Member Since
    Sep 13, 2009
    Posts
    2
    The order you declare variables in your .h file may be the problem. in a project I was working on today I found that
    Code:
    double var_price[17];
    NSString *var_name[17];
    int var_stock[17];
    NSString *var_itemcode[17];
    int var_maxstock[17];
    int var_arrayno;
    returned the EXC_BAD_ACCESS error but after changing the order of things the error went away.
    Code:
    NSString *var_name[17];
    NSString *var_itemcode[17];
    double var_price[17];
    int var_stock[17];
    int var_maxstock[17];
    int var_arrayno;
    I have no idea why reordering things fixed the problem and it took me hours to find it in the project. The idea "hmm, maybe the variables are declared in the wrong order in the header file" isn't the first thought that came to mind and theoretically I would not think it would make a difference but you can't argue with results

  4. #4
    NSMutableArry and “EXC_BAD_ACCESS”

    Member Since
    Sep 13, 2009
    Posts
    2
    Just worked out what was causing my problem yesterday, it seems that if you declare
    Code:
    someobject* anarray[2]
    this in objective C (correct me if i'm wrong) means the array size is 2
    Code:
    anarray[0] //valid
    anarray[1] //valid
    anarray[2] //invalid
    This caught me out because I program in vb and the last one would be valid in that language. The data that was being written outside of the array was in fact being written to the first memory location of the next array hence when the program tried to read something from the second array and information from the double was in the NSString array the program crashed. However I then after rearranging the variables found strings from the end of the first array popping up in the beginning of the second not crashing the program as they were both the same data type.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 03-10-2015, 10:47 PM
  2. Office Mac 2004 crashes Exception: EXC_BAD_ACCESS
    By caincha in forum OS X - Apps and Games
    Replies: 7
    Last Post: 02-12-2013, 05:34 PM
  3. Mac Mail Crashing - EXC_BAD_ACCESS (SIGBUS)
    By callmeanidiot in forum OS X - Operating System
    Replies: 0
    Last Post: 01-09-2013, 10:00 AM
  4. Replies: 2
    Last Post: 04-19-2011, 06:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •