How to implement 'undo' feature

A “complex action” in this context is just a collection of smaller undo actions which are either undone or redone together. What concerns you about them?

1 Like

but remember “undo” and “redo” only happen if the user uses undo and redo. So even if my fully custom action has a faulty undo or redo, they won’t run unless the user does it intentionally. I guess an exception would be your destructor. Presumably all actions get “destroyed” when you load a new patch?

fwiw, every modern app that I’ve worked on keeps undo in memory “forever”. And on a modern OS you never run out of memory and crash, you start paging and the programs gets sluggish.

Most actions are tinny. The ones in my sequencer could potentially have a copy of every note (if you select all and delete I’m going to save off all those notes first).

Just that it seems that crashes sometimes seem to occur while editing patches after a selection file has bee loaded or deleting a selection. But, it is hard to tell. I’ve had a couple of very knowledgeable developers help me on this problem, but even under debug, they were not able to trace what was causing the crashes, even though with one of the developers, I produced a test patch that was pretty much guaranteed to crash on the n-th reset to modules.

But, this is off topic. I’ve taken this mentioned crash as far as I am willing to take it. It seems very deep and insidious to me.

Does this imply that the undo history is only kept for the current patch execution and that any load or reload clears the history?

Unfortunately yes, just try it out.

Yes, this appears to be the case, which is good IMHO.

Some major applications provide a mechanism to clear the undo history in case something gets corrupted. But as long as the history does not get serialized, it should be okay that the history gets cleared on any launch of Rack and on patch load or reload.

I hope that developer implementations of undo also likewise do not serialize and do not corrupt memory or do anything that can break the Rack patch manager code.

One can but hope.

1 Like

Any dev who is worried about this should run their plugin under address sanitizer or valngrind to verfy they are doing memory management correctly.