Fix T54568: Undo memory de-duplication failed

Error in 651b8fb14e caused de-duplication to fail.
This commit is contained in:
Campbell Barton 2018-04-14 12:30:14 +02:00
parent 332846b188
commit 2e9b92b5cc
Notes: blender-bot 2023-02-14 06:03:03 +01:00
Referenced by issue #54568, More than 100Mb of memory allocation per click-selection
3 changed files with 13 additions and 1 deletions

View File

@ -149,6 +149,7 @@ bool BKE_undosys_step_push_with_type(UndoStack *ustack, struct bContext *C, cons
bool BKE_undosys_step_push(UndoStack *ustack, struct bContext *C, const char *name);
UndoStep *BKE_undosys_step_find_by_name_with_type(UndoStack *ustack, const char *name, const UndoType *ut);
UndoStep *BKE_undosys_step_find_by_type(UndoStack *ustack, const UndoType *ut);
UndoStep *BKE_undosys_step_find_by_name(UndoStack *ustack, const char *name);
bool BKE_undosys_step_undo_with_data_ex(UndoStack *ustack, struct bContext *C, UndoStep *us, bool use_skip);

View File

@ -500,6 +500,16 @@ UndoStep *BKE_undosys_step_find_by_name(UndoStack *ustack, const char *name)
return BLI_rfindstring(&ustack->steps, name, offsetof(UndoStep, name));
}
UndoStep *BKE_undosys_step_find_by_type(UndoStack *ustack, const UndoType *ut)
{
for (UndoStep *us = ustack->steps.last; us; us = us->prev) {
if (us->type == ut) {
return us;
}
}
return NULL;
}
bool BKE_undosys_step_undo_with_data_ex(
UndoStack *ustack, bContext *C, UndoStep *us,
bool use_skip)

View File

@ -70,9 +70,10 @@ static bool memfile_undosys_step_encode(struct bContext *C, UndoStep *us_p)
/* Important we only use 'main' from the context (see: BKE_undosys_stack_init_from_main). */
struct Main *bmain = CTX_data_main(C);
UndoStack *ustack = ED_undo_stack_get();
/* can be NULL, use when set. */
MemFileUndoStep *us_prev = (MemFileUndoStep *)BKE_undosys_step_same_type_prev(us_p);
MemFileUndoStep *us_prev = (MemFileUndoStep *)BKE_undosys_step_find_by_type(ustack, BKE_UNDOSYS_TYPE_MEMFILE);
us->data = BKE_memfile_undo_encode(bmain, us_prev ? us_prev->data : NULL);
us->step.data_size = us->data->undo_size;
return true;