On 16/09/2009, at 1:17 PM, Graham Cox wrote:

I guess it's time to strip this down to a small reproducible case I can give them...


OK, narrowing it down, the problem seems to be an interaction between NSTextView and NSUndoManager. So far I've discovered that:

1. If I disable undo for the text view (-setAllowsUndo:NO) I get no problem. 2. the actual target registered with the undo manager by the text view is its text storage. That makes sense - it's the data model therein. 3. I am re-using the textview for different edits, much like the field editor. This involves replacing the text storage for a new edit, by calling -replaceTextStorage on the text view's layout manager. Then, undo fails because the targeted text storage no longer exists:

*** -[NSConcreteTextStorage _undoRedoTextOperation:]: message sent to deallocated instance 0x152cb9d0

4. To prevent the above, when editing ends I remove all undo tasks having the storage as a target. [[theEditor undoManager] removeAllActionsWithTarget:[theEditor textStorage]];

This is OK for my app since the typing doesn't need to be undoable outside of editing (in fact it's undesirable) - the wholesale change to an object's text is undoable anyway. So the undo needs only to be operative while editing is active. Thus removing all such undo tasks when editing ends seems to be the right thing to do. It is this that triggers the original problem with _NSUndoBeginMark. I don't think - removeAllActionsWithTarget is correctly removing the begin marks.

This does seem to be it - taking out that one line, and replacing the contents of the storage, rather than the storage itself, all is well. It means I end up with a bunch of undo tasks "Undo Typing" that do nothing (since the editor in question is no longer shown), or else I disable undo and don't get undoable typing while the editor is active. Neither is ideal but it's better than crashing.

So, the real problem seems to be that there's no way to remove typing tasks from the undo stack following an edit operation, since attempting to do so triggers the mark over-release in the undo manager. I think I have enough to file a bug report.

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to