Debugging undo stack issues

What is the best way to debug issues with the undo stack. I have a certain circumstance that adds three items to the undo stack. I would like to do something like puts, so I can check in my code where the items are being added. I think the issue is most likely in an observer, but I’m unsure how to tell because when stepping through the code SketchUp is froze, and I can’t check the undo menu in the UI.

There is the log text file that is written into by SketchUp. In the LocalAppData/temp folder.
You can sometimes watch that file using a logfile viewer utility or an editor.

The undo stack is not itself exposed to the APIs. We have long asked to be able to get the current undo operation’s name, but it hasn’t yet been implemented.

The only notifications of transactions is via a Sketchup::ModelObserver object.

onTransactionStart (model) might be useful if the transaction name would be passes as an argument.

The log doesn’t look particularly useful in this case.

You can read the name of the last transaction in both the Undo and Redo stack in the Edit menu. This is not exposed by the API though.

I know. I was hoping for some sort of hack I guess. I was able to find my problem, but it would have been easier if I could have checked the undo stack from the api.

Well, on Windows you could use a MS MFC C function call to perhaps read the Edit menu captions.

From all the undo’s I find ‘reparent’ the most intriguing one
Of topic, srry!

I’ve sometimes had to debug extension behaviours, in which I hooked model.start/commit/abort_operation calls in the API and then used that to either dump a message in the Ruby console or set a breakpoint. This off source only work for Ruby operation and omits any native operations invoked.

My problem was that somewhere in my code I was writing to attributes dictionaries in code that was expecting to be in a transaction. I can’t remember exactly how I found it. I think I ended up commenting things out until the problem went away.

Ah, so it’s be an implicit operation, by for instance adding an attribute or any other model change without an active operation?

If you think you know what method does it, then you can try to hook that.

That is a little how I did it.

  1. Figure out what set of circumstances make the issue happen. (reproduction steps)
  2. Figure out what all code is being called in the circumstances. (including Observers and such)
  3. Use process of elimination to figure out which chunk of code causes the problem.
  4. Fix the problem and release the new version.
  5. Deal with support issues from people with the old version still installed.

This was a particularly bad one because an undo observer indirectly triggered some code that inadvertently added transactions to the undo stack, essentially making it impossible to undo! :frowning:

1 Like