Re: EXEC_BAD_ACCESS crash when using encodeObject:forKey: on an NSString *.
Re: EXEC_BAD_ACCESS crash when using encodeObject:forKey: on an NSString *.
- Subject: Re: EXEC_BAD_ACCESS crash when using encodeObject:forKey: on an NSString *.
- From: August Trometer <email@hidden>
- Date: Tue, 26 Apr 2005 23:44:00 -0500
I think you need to end your list of objects with a nil...
NSArray *arr = [NSArray arrayWithObjects: mA, mB, nil];
-- August
On Apr 26, 2005, at 11:36 PM, Andrew White wrote:
XCode 1.5, MacOS X 10.3.9
Reported this as a bug, but I thought I'd check here too in case
anyone else knows a good workaround or can point out a stupid error.
#import <Foundation/Foundation.h>
@interface DemoObject : NSObject <NSCoding>
{
NSString * mStr;
NSMutableArray * mA;
NSMutableArray * mB;
}
@end
@implementation DemoObject
- (id) init
{
self = [super init];
if (! self)
{
return nil;
}
mStr = @"Hello";
[mStr retain];
mA = [[NSMutableArray alloc] init];
mB = [[NSMutableArray alloc] init];
return self;
}
// Coder keys
static NSString * const kKeyString = @"String";
static NSString * const kKeyArrays = @"Arrays";
- (void) encodeWithCoder: (NSCoder *) coder
{
if ([coder allowsKeyedCoding])
{
[coder encodeObject: mStr forKey: kKeyString ];
NSArray * arr = [NSArray arrayWithObjects: mA, mB];
// ^ this line crashes
[coder encodeObject: arr forKey: kKeyArrays];
}
}
@end
When I call
DemoObject * obj = [[[DemoObject alloc] init] autorelease];
[NSKeyedArchiver
archiveRootObject: obj toFile: @"testFile"
];
the code reliably crashes in CFRetain with an EXEC_BAD_ACCESS error
when I trying to create the array. If I remove the call to
[coder encodeObject: mStr forKey: kKeyString ];
then everything works as expected.
Any thoughts?
_______________________________________________
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