• 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
EXEC_BAD_ACCESS crash when using encodeObject:forKey: on an NSString *.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

EXEC_BAD_ACCESS crash when using encodeObject:forKey: on an NSString *.


  • Subject: EXEC_BAD_ACCESS crash when using encodeObject:forKey: on an NSString *.
  • From: Andrew White <email@hidden>
  • Date: Wed, 27 Apr 2005 14:36:30 +1000


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?

--
Andrew White

--------------------------------------------------------------------------
This email and any attachments may be confidential. They may contain legally
privileged information or copyright material. You should not read, copy,
use or disclose them without authorisation. If you are not an intended
recipient, please contact us at once by return email and then delete both
messages. We do not accept liability in connection with computer virus,
data corruption, delay, interruption, unauthorised access or unauthorised
amendment. This notice should not be removed.
_______________________________________________
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


  • Follow-Ups:
    • Re: EXEC_BAD_ACCESS crash when using encodeObject:forKey: on an NSString *.
      • From: August Trometer <email@hidden>
  • Prev by Date: Re: ADC Select Membership
  • Next by Date: Re: EXEC_BAD_ACCESS crash when using encodeObject:forKey: on an NSString *.
  • Previous by thread: Best way to implement an iMovie like clip tray?
  • Next by thread: Re: EXEC_BAD_ACCESS crash when using encodeObject:forKey: on an NSString *.
  • Index(es):
    • Date
    • Thread