Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Problem adding objects to NSMutableArray

I am having problems adding objects to my NSMutableArray. It seems that something gets added (object count increases by 1 in debugger), but the only thing added is a 0x0 (null) instead of the address of an object. I've read through everything somewhat relevant that I could find, but I couldn't find anything that seemed to answer this issue. Most related posts seem to revolve around memory management, but the solution is not jumping out at me.

I appreciate any help you can provide.

I've included what I think are the relevant parts of the code. Please tell me if you need to see anything more.

Within GamePlayView.h

@interface GamePlayView : UIViewController {

Player *gamePlayer;
NSMutableArray *boardObjects;

}

@property (retain, nonatomic) Player *gamePlayer;
@property (retain, nonatomic) NSMutableArray *boardObjects;

@end


Within GamePlayView.m

- (void)viewDidLoad {

// Create player

Player *tempPlayer = [[Player alloc] initWithFrame: self.view.frame];
if (tempPlayer == NULL) {
NSLog(@\"GamePlayView viewDidLoad: null Player\");
}
else self.gamePlayer = tempPlayer;

// Create array of board objects

NSMutableArray *newArray = [[NSMutableArray alloc] init];

self.boardObjects = newArray;
[self.boardObjects addObject: gamePlayer]; // First breakpoint here
topObject = 0;

BoardObject *mine = [[BoardObject alloc] initWithFrame: self.view.frame];

[self.boardObjects addObject: mine]; // Second breakpoint here
topObject = 1;

[super viewDidLoad];

} // End viewDidLoad


I put breakpoints at the addObject lines (commented in code). When execution stops at the first breakpoint, the debugger shows a good tempPlayer, and a good gamePlayer (both non-null, with the same address). It shows 0 objects in boardObjects, like this:
boardObjects = (_NSArrayM *) 0x4b22080 0 objects
When I step over this breakpoint, the debugger shows 1 object in boardObjects, as follows:
boardObjects = (_NSArrayM *) 0x4b22080 1 objects
0 = (NSObject *) 0x0

When I continue program execution, and the debugger stops at the next breakpoint, I also see a good mine object, with boardObjects still described as above. After stepping over this breakpoint, boardObjects now looks like this:
boardObjects = (_NSArrayM *) 0x4b22080 2 objects
0 = (NSObject *) 0x0
1 = (NSObject *) 0x0
Post edited by Magoolah on

Replies

Sign In or Register to comment.