Fix #36748 Sculpting/image painting does not respect undo steps limit.
authorAntony Riakiotakis <kalast@gmail.com>
Tue, 17 Sep 2013 12:11:00 +0000 (12:11 +0000)
committerAntony Riakiotakis <kalast@gmail.com>
Tue, 17 Sep 2013 12:11:00 +0000 (12:11 +0000)
A simple oversight here, it should work as intended now.

Nice to have it functional for people who might hate dyntopo undo with a
passion.

source/blender/editors/sculpt_paint/paint_undo.c

index e406d4f5c3b593cc148de682c198a822a16981df..50a79005ee33558e57c217b51a2957b67d912e2a 100644 (file)
@@ -124,6 +124,30 @@ static void undo_stack_push_end(UndoStack *stack)
 {
        UndoElem *uel;
        uintptr_t totmem, maxmem;
+       int totundo = 0;
+
+       /* first limit to undo steps */
+       uel = stack->elems.last;
+
+       while (uel) {
+               totundo++;
+               if (totundo > U.undosteps) break;
+               uel = uel->prev;
+       }
+
+       if (uel) {
+               UndoElem *first;
+
+               /* in case the undo steps are zero, the current pointer will be invalid */
+               if (uel == stack->current)
+                       stack->current = NULL;
+
+               do {
+                       first = stack->elems.first;
+                       undo_elem_free(stack, first);
+                       BLI_freelinkN(&stack->elems, first);
+               } while (first != uel);
+       }
 
        if (U.undomemory != 0) {
                /* limit to maximum memory (afterwards, we can't know in advance) */