for my tile editor I have 2 stacks of TileMaps, undo and redo. Every time the user makes a change the state of the map is added to the stack, than the change is made. Here is my undo code:
private void undoToolStripMenuItem_Click(object sender, EventArgs e)
{
if (undo.Count != 0)
{
redo.Push(tileMap);
tileMap = undo.Peek();
undo.Pop();
}
}
The map however does not change. Why?
If it’s not a UI update issue…
Are your redo and undo references to different stack objects? If they both reference the same stack object, then your code would just push-and-pop the current state.
Or similarly, are you pushing another reference to the same tileMap object, or a copy of it? (i.e. You probably want to
Push(tileMap.DeepCopy()))Also, why do you Peek and then Pop? You can just Pop directly into tileMap.