On 18/08/2009, at 7:43 AM, Jerry Krinock wrote:

On 2009 Aug 17, at 12:50, Alastair Houghton wrote:

All this makes sense. Then, by extension, "too many nested undo groups" implies that -groupingLevels is too high. But by default, -levelsOfUndo is inifinite.

Levels of undo and nested undo groups are separate things, I think. The message is most likely being generated because you're missing an -endUndoGrouping message somewhere.

The message appears when I click 'Undo'.  Here it is in its entirety:

"undo: NSUndoManager 0x164f7ef0 is in invalid state, undo was called with too many nested undo groups"

Documentation says that "-undo closes the last open undo group and then applies all the undo operations in that group. ... If any unclosed, nested undo groups are on the stack when undo is invoked, it raises an exception."

So if you interpret "nested" in this document to be "more than one open" and "too many" in the log message to be "more than one", this may be the exception I'm seeing.

Thanks, Alastair. I'll check that out. So maybe what they're trying to say with that log message is "... undo was called with more than one open (nested) undo group".


This is definitely caused by a missing -endUndoGrouping message.

However, this can be a nightmare to deal with in a nice way. First, there's the NSUndoManager bug where opening a group and closing a group but doing nothing else in between creates a bogus "Undo" task that doesn't do anything except pollute the Undo stack. So you need to code around that one by only opening the group if you really are going to put something on the Undo stack. Then having done that you need to make sure you make a note of that so that you can close the group as needed to avoid the error you're seeing here.

That's bad enough, but if there's also the chance of an exception being thrown, you need to catch it and make sure that if you did open a group, it gets closed as part of the exception clean up.

Where you can, avoid opening and closing undo groups yourself. A default group is opened by the event loop so if that is adequate it can save a lot of headaches.

--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