Re: Program Crash
Re: Program Crash
- Subject: Re: Program Crash
- From: Steven Kramer <email@hidden>
- Date: Wed, 22 Sep 2004 11:24:43 +0200
Another coincidence
(http://lists.apple.com/archives/cocoa-dev/2004/Sep/msg00727.html).
I've encountered this problem numerous times (including the exact
callstack leading up to CFArrayGetCount) and yesterday wrote a little
debugging tool. I pasted the code below, I think it could be of some
use in this case.
From my experience with this kind of thing, I'd say you are either
binding to File's Owner in the document's nib, or you are binding to an
outlet of File's Owner. Try binding to Shared
Application.mainWindow.windowController.document instead, and implement
setters and getters for the outlets in your document class.
If that is a lot of work, try debugging with my code first. It will
allow you to better pinpoint the object causing the trouble (because
you will have source debugging in the release method and you can
inspect the bound properties from there).
Steven
Op 22-sep-04 om 11:04 heeft Jacob Lukas het volgende geschreven:
I'm writing a document-based program called Time It, and whenever I
close a document, the program crashes. It seems that it's trying to
remove an observer but something is nil. I'm having a hard time
debugging it as none of my classes are directly related to the crash.
// Usage: call poseAsClass as soon as possible in your app as follows
[ClassThatSeemsToHaveUnfixableBindingBugPoser poseAsClass:
[ClassThatSeemsToHaveUnfixableBindingBug class]];
// And put this somewhere - don't forget to replace NSDocument by the
class you're interested in (or NSObject if you don't mind a lot of
overhead)
static NSMutableDictionary* boundKeys = [NSMutableDictionary new];
static NSMutableDictionary* boundObjects = [NSMutableDictionary new];
typedef NSDocument ClassThatSeemsToHaveUnfixableBindingBug;
@interface ClassThatSeemsToHaveUnfixableBindingBugPoser : NSDocument
@end
@implementation ClassThatSeemsToHaveUnfixableBindingBugPoser
- (void)bind:(NSString *)binding toObject:(id)observable
withKeyPath:(NSString *)keyPath options:(NSDictionary *)options
{
[super bind: binding toObject: observable withKeyPath: keyPath
options: options];
id Self = [NSString stringWithFormat: @"%x", self];
NSMutableArray* keys = [boundKeys objectForKey: Self];
if (!keys) {
keys = [[NSMutableArray new] autorelease];
[boundKeys setObject: keys forKey: Self];
}
[keys addObject: keyPath];
}
- (void)unbind:(NSString *)binding;
{
[super unbind: binding];
id Self = [NSString stringWithFormat: @"%x", self];
NSMutableArray* keys = [boundKeys objectForKey: Self];
[keys removeObject: binding];
}
- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath
options:(NSKeyValueObservingOptions)options context:(void *)context;
{
[super addObserver: observer forKeyPath: keyPath options: options
context: context];
id Self = [NSString stringWithFormat: @"%x", self];
NSMutableArray* bindings = [boundObjects objectForKey: Self];
if (!bindings) {
bindings = [[NSMutableArray new] autorelease];
[boundObjects setObject: bindings forKey: Self];
}
[bindings addObject: [NSArray arrayWithObjects: observer, keyPath,
nil]];
}
- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString
*)keyPath
{
[super removeObserver: observer forKeyPath: keyPath];
id Self = [NSString stringWithFormat: @"%x", self];
NSMutableArray* bindings = [boundObjects objectForKey: Self];
[bindings removeObject: [NSArray arrayWithObjects: observer, keyPath,
nil]];
}
- (void) dealloc
{
id Self = [NSString stringWithFormat: @"%x", self];
NSMutableArray* bindings = [boundObjects objectForKey: Self];
if ([bindings count]) {
NSLog (@"You have some observers observing!\n%@", bindings);
}
[super dealloc];
}
- (oneway void) release
{
id Self = [NSString stringWithFormat: @"%x", self];
[super release];
Self = nil;
}
@end
_______________________________________________
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