*Help* with mysterious crash... CFRetain related
*Help* with mysterious crash... CFRetain related
- Subject: *Help* with mysterious crash... CFRetain related
- From: Johnny Deadman <email@hidden>
- Date: Thu, 7 Apr 2005 09:42:08 -0400
I am very sorry to bother the list with this but I am totally out of
ideas on what is causing this crash.
I have a subclass of NSTextView which over-rides -typingAttributes to
behave a little more predictably (there are circumstances where it
inappropriately returns 'nil'- that is a story in itself).
Mostly it works just fine, but one of the lines causes a crash a few
moments later. If I comment this line out, the crash doesn't happen.
I have marked this in the source below.
The crash seems to occur when a textField in the main editor window,
which is bound to a value for a key in the typing attributes
(layoutManager.firstTextView.typingAttributes.GLElementStyle),
attempts to update. This is triggered in turn by a [textStorage
endEditing] message.
The mysterious part is that the crash does not immediately follow a
call to the error-causing line, but to the first 'if (attributes !=
nil)' line. This returns a dictionary with a retain count of 1 which
contains the required key (see log below). Adding 'retain's to the
returned dictionary does not help, so I do not think it is a simple
premature release. I have zombies enable but nothing is showing up.
The method is as follows:
- (NSDictionary *)typingAttributes
{
NSDictionary *attributes = [super typingAttributes];
if ( attributes != nil ){
NSLog (@"Branch 1: Attributes retain count is: %d",
[attributes retainCount]);
NSLog (@"Attributes: %@", attributes);
return attributes;
}
// nil attributes so first attempt to inspect the character to
the right
int location = [self selectedRange].location;
if ( location < [[self textStorage] length] )
attributes = [[self textStorage] attributesAtIndex:location
effectiveRange:nil];
// we must be at EOF: if storage is non-nil then we can look
// at the character to the left (location - 1 >= 0)
//*** THIS IS THE LINE THAT CAUSES THE CRASH ***
else if ([[self textStorage] length] != 0 )
attributes = [[self textStorage] attributesAtIndex: location-1
effectiveRange: nil];
// the textStorage is empty: return an empty dictionary
else attributes = [NSDictionary dictionary];
return attributes;
}
Here is the log that immediately precedes the crash:
2005-04-07 09:14:28.277 Greenlight-Tiger[1393] Branch 1: Attributes
retain count is: 1
2005-04-07 09:14:28.279 Greenlight-Tiger[1393] Attributes: {
GLCapitalized = 0;
GLElementStyle = Slugline;
<everything else is just what you would expect>
}
Here is the crash log:
Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000006
Thread 0 Crashed:
0 com.apple.CoreFoundation 0x9072d008 CFRetain + 60
1 com.apple.Foundation 0x928f9a3c
_NSKeyValueObservationInfoCreateByRemoving + 440
2 com.apple.Foundation 0x928f9814 -[NSObject
(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 56
3 com.apple.Foundation 0x928f9704 -[NSObject
(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 436
4 com.apple.Foundation 0x928fa36c -
[NSKeyValueObservationForwarder
observeValueForKeyPath:ofObject:change:context:] + 268
5 com.apple.Foundation 0x92882298 -[NSObject
(NSKeyValueObserverNotification) didChangeValueForKey:] + 512
6 com.apple.AppKit 0x936d7d00 -[NSTextView(NSSharing)
setSelectedRanges:affinity:stillSelecting:] + 2924
7 com.apple.AppKit 0x9368b560 -[NSLayoutManager
(NSPrivate) _fixSelectionAfterChangeInCharacterRange:changeInLength:]
+ 820
8 com.apple.AppKit 0x936876a8 -[NSLayoutManager
textStorage:edited:range:changeInLength:invalidatedRange:] + 904
9 com.apple.AppKit 0x93687300 -[NSTextStorage
_notifyEdited:range:changeInLength:invalidatedRange:] + 140
10 com.apple.AppKit 0x936e9a68 -[NSTextStorage
processEditing] + 188
11 com.apple.AppKit 0x936850dc -[NSTextStorage
edited:range:changeInLength:] + 284
12 com.apple.Foundation 0x92889ad8 -
[NSConcreteMutableAttributedString
replaceCharactersInRange:withAttributedString:] + 388
13 com.apple.AppKit 0x936fcbd4 -[NSConcreteTextStorage
replaceCharactersInRange:withAttributedString:] + 80
14 com.deepfried.greenlight 0x000032c4 -[GLScreenplayDocument
windowControllerDidLoadNib:] + 884 (GLScreenplayDocument.m:157)
_______________________________________________
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