NSMutableArray access problem
NSMutableArray access problem
- Subject: NSMutableArray access problem
- From: Christopher Corbell <email@hidden>
- Date: Sat, 03 Aug 2002 18:07:46 -0700
I've hit on a problem with NSMutableArray which seems like it might
be a bug; it's a pretty specific context but I find it to be reproducible.
I wonder if anyone else has seen this or can explain it.
I'm using an NSMutableArray in a data-source for an NSTableView.
The message that provides the number of rows in the table
view simply returns the result of the array's [count] message.
The method is called several times while a window containing
the table is being loaded (along with connected data source,
delegate, etc.) from a window-specific .nib file.
The first three calls to this method work fine, but the fourth call
fails. The first three calls happen before the window
is completely loaded from the nib; the fourth call happens after this.
Here is the code which produces the error, with a couple of
statements to trace the address of the array and its value:
- (int)numberOfRowsInTableView:(NSTableView *)tableView
{
printf("m_records: 0x%x\n", (unsigned)m_records);
printf("[m_records count]: %d\n", (int)[m_records count]);
return [m_records count];
}
Here is the runtime output
m_records: 0x1b488c0
[m_records count]: 0
m_records: 0x1b488c0
[m_records count]: 0
m_records: 0x1b488c0
[m_records count]: 0
window is loaded.
m_records: 0x1b488c0
ProtoTable has exited due to signal 10 (SIGBUS).
When I step through in the debugger, the local variables
in this routine are listed as "out of scope" on the fourth call and
I get EXC_BAD_ACCESS when stepping over the [count] message.
The call stack includes:
- [NSTableView drawRect]
...
- [NSWindow makeKeyAndOrderFront]
- [NSWindowController showWindow]
Any idea what causes this? If I substitute the [count] message with
a redundant int field in the data-source which keeps track of the
array size, and just return the int member in the above method,
everything works fine. This is a workaround but I'd like to know
if there is something about NSMutableArray and similar containers
that causes this, or if the source of the problem must be elsewhere...
TIA,
Chris
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.