[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
Serious bug in NSTextView (and a fix)
From:
Ludovic Marcotte
Subject:
Serious bug in NSTextView (and a fix)
Date:
2001年10月19日 10:24:54 -0400 (EDT)
In NSTextView: -_updateMultipleTextViews, we have:
if ([[_layoutManager textContainers] count] > 1)
{
_tvf.multiple_textviews = YES;
_notifObject = [_layoutManager firstTextView];
}
else
{
_tvf.multiple_textviews = NO;
_notifObject = self;
}
So, _notifObject can be equal to self (our NSTextView instance).
When -dealloc is called on NSTextView, -dealloc is called on
NSText and on NSView.
In NSView -dealloc, we call NSView: -_unregisterDraggedTypes. This
method calls _removeDragTypes from
xgps/Source/SharedX/XGContextEvent.m.
The problem here is that we can have a crash in _removeDragTypes
since "self" (our NSTextView object) can still be referenced by
an object in the autorelease pool and get released.
The object itself, is a NSNotification object created when we post
five critical notifications those NSTextView's methods:
NSTextView: -setRulerVisible
NSTextView: -shouldChangeTextInRange: replacementString
NSTextView: -didChangeText
NSTextView: -resignFirstResponder
NSTextView: -_illegalMovement:
Actually, IMO, only -resignFirstResponder can be problematic. We
can safely replace in NSTextView.m:
- (BOOL) resignFirstResponder
{
...
...
[nc postNotificationName: NSTextDidEndEditingNotification
object: _notifObject];
return YES;
}
by:
- (BOOL) resignFirstResponder
{
NSNotification *aNotification;
..
aNotification = [[NSNotification alloc]
initWithName: NSTextDidEndEditingNotification
object: _notifObject
userInfo: nil];
[nc postNotification: aNotification];
RELEASE(aNotification);
return YES;
}
To be *sure* that our NSTextView object won't be retained by an object
(a NSNotification object) in an autorelease pool.
I've done extensive testing for that with GNUMail.app and I can tell
that it works and solve the problem.
Thanks a lot,
Ludo
--
Live as if you were to die tomorrow.
Learn as if you were to live forever.
- Gandhi
- Serious bug in NSTextView (and a fix),
Ludovic Marcotte <=