• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSFileHandle crashes after a loop completes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSFileHandle crashes after a loop completes


  • Subject: NSFileHandle crashes after a loop completes
  • From: "Matthew Callis" <email@hidden>
  • Date: Sun, 14 Jan 2007 00:37:35 -0600

I have a function to read information from files based on their extension.
Everything goes fine until it gets to the last file, the method never Exits
and the program crashes. I cannot see where my error is or if there even is
an error, I might just be wrong and it's a different error. It goes through
it's routine if you pass it only the file name and doesn't crash, but as
expect it doesn't return anything and I don't know why this doesn't crash
and the other does.
The function to select the file extension  and pass along the fullPath is:

+ (FileReader *) parseFile:(NSString *)fullPath{
FileReader *result = nil;
NSString *pathExtension = [[fullPath pathExtension] lowercaseString];

if([pathExtension isEqualToString:@"game"]){
 result = [[GameReader alloc] initWithFile:fullPath];
}
else{...}
return [result autorelease];
}

- (id) initWithFile:(NSString *)fullPath;{
if((self = [super init])){
 _metadata = [NSMutableDictionary retain];
 _fullPath = [fullPath retain];
 return self;
}
return nil;
}

The Data then goes to this function:

- (id) initWithFile:(NSString *)fullPath{
if((self = [super initWithFile:fullPath])){
 [self readMetadata];
 return self;
}
return nil;
}

- (void) readMetadata{
NSMutableDictionary *metadataDictionary = [NSMutableDictionary dictionary];

NSFileHandle *fileHandle = [NSFileHandle
fileHandleForReadingAtPath:_fullPath];
NSData *Buffer;
NSString *FileCRC32; // returns: fileCRC32

Buffer = [fileHandle readDataToEndOfFile];
FileCRC32 = [NSString stringWithFormat:@"0xx", [Buffer crc32]];
[metadataDictionary setValue:FileCRC32 forKey:@"fileCRC32"];

[Buffer release];
[fileHandle closeFile];

[self setValue:metadataDictionary forKey:@"metadata"];
}

Then I call the data with this and it shows the data then crashed after
writing the data to file:

FileReader *metadataReader;
metadataReader = [FileReader parseFile:fullPath];
NSDictionary *metadata = [metadataReader valueForKey:@"metadata"];
NSLog(@"Checksum: %@", [metadata valueForKey:@"fileCRC32"]);


-- - Matthew http://eludevisibility.org/ _______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSFileHandle crashes after a loop completes
      • From: Chris Suter <email@hidden>
  • Prev by Date: Doubleclick document...Which app ^instance^ launches?
  • Next by Date: Re: NSFileHandle crashes after a loop completes
  • Previous by thread: Re: Doubleclick document...Which app ^instance^ launches?
  • Next by thread: Re: NSFileHandle crashes after a loop completes
  • Index(es):
    • Date
    • Thread