Re: newbie EXC_BAD_ACCESS
Re: newbie EXC_BAD_ACCESS
- Subject: Re: newbie EXC_BAD_ACCESS
- From: Daniel Child <email@hidden>
- Date: Sun, 20 Mar 2005 13:17:17 -1000
Thanks for clarifications! How do you get and read a backtrace? (I'm using ProjectBuilder.)
You suggested I show the fillStrokes method. Here it is.
// This method reads in stroke values from a flat file that is in the same
// folder as this project. The file contains tab-separated fields, with a
// return for each record. This method parses the file into lines, and then into
// fields for each line so that it can be placed in the knownStrokes array.
- (void)fillKnownStrokes
{
NSCharacterSet *chSetTab, *chSetRtn; // token parsers
NSString *scannedName, *string;
NSScanner *scanner; // essentially a tokenizer
NSString *stringArray[44];
NSNumber *thisType;
NSString *thisDesc;
StrokeDescription *sd = [[StrokeDescription alloc] init];
int i = 0, j = 0;
// Initially, you place the entire file contents into one string.
string = [NSString stringWithContentsOfFile:
[@"~/Documents/PROGRAMMING/IME DEV/ScratchPad/strokeList.txt" stringByExpandingTildeInPath]];
chSetRtn = [NSCharacterSet characterSetWithCharactersInString:@"\n"];
chSetTab = [NSCharacterSet characterSetWithCharactersInString:@"\t"];
scanner = [NSScanner scannerWithString:string];
// Now break up each line so that each line is in the array.
while(![scanner isAtEnd]) {
if([scanner scanUpToCharactersFromSet:chSetRtn intoString:&scannedName]) {
stringArray[i] = scannedName;
i++;
}
[scanner scanCharactersFromSet:chSetTab intoString:nil];
}
for (i = 0; i < 44; i++)
{
// now give scanner each full line of text one line at a time
scanner = [NSScanner scannerWithString: stringArray[i]];
for (j = 0; j < 2; j++)
{
[scanner scanUpToCharactersFromSet: chSetTab intoString: &scannedName];
if (j == 0)
{
thisType = [NSNumber numberWithInt: [scannedName intValue]];
[sd setStrokeType: thisType];
// printf("thisType is %i\n", [thisType intValue]);
} // end if
else
{
thisDesc = scannedName;
[sd setDesc: thisDesc];
// printf("thisDesc is %s\n", [thisDesc cString]);
} // end else
[self addStrokeDesc: sd];
} // end inner for
} // end outer for
[sd release];
}
On Sunday, March 20, 2005, at 11:01 AM, Charilaos Skiadas wrote:
On Mar 20, 2005, at 2:50 PM, Daniel Child wrote:
Unfortunately, the suggestions below do not work. I still get the crash. I had also printed out retain counts on knownStrokes.
It might help if you show us the code for fillKnownStrokes, the new code you tried, and the backtrace of the crash. In fact, if you look at the backtrace, that should tell you exactly where the problem is.
One thing I don't understand. If I create an instance of StrokesArray "sa" having an instance variable knownStrokes, why should I have to specially retain knownStrokes. Shouldn't it come with sa itself.
Whoever creates "sa" doesn't have to retain knownStrokes. However, the instance "sa" of StrokesArray, when *it* is created, *it* creates knownStrokes, so *it* has to retain it, because it needs it. (I actually prefer not to think of it in terms of retain, but in terms of *own*. sa needs to own knownStrokes, so it needs to either alloc/init it, or retain the autoreleased object return by arrayWithCapacity.) Anyone who creates StrokesArray's from now on doesn't need to worry about knownStrokes, that's the StrokesArray instance's job.
Also, why do I have to specify the initial capacity of knownStrokes in the first place. Is there an advantage to the capacity methods below compared to plain old alloc/init?
You don't have to specify the initial capacity, though it helps the system slightly if you do. It should not really affect performance at this level (i.e. 100 elements). But if you ask the array eventually to handle 100000 elements, then it might help it if it knows about it in advance, so it can arrange how to store them.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden