diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-07-23 19:27:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-23 19:27:51 +0200 |
commit | e0d48f87f9cd3ab9685a55145215e8de45f905a8 (patch) | |
tree | 68284b83874e26bfbe8b3b072d0f388f9b2f3772 | |
parent | eefc67a810975cb99343554c981968ea5ae2fd3e (diff) | |
parent | c3baf83e2816a1438604b12ac626378f09f6cc18 (diff) |
Merge pull request #50782 from timothyqiu/undoredo-ref
Fix UndoRedo crash when clearing history
-rw-r--r-- | core/object/undo_redo.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/core/object/undo_redo.cpp b/core/object/undo_redo.cpp index 0532b2ae40..6808d7602d 100644 --- a/core/object/undo_redo.cpp +++ b/core/object/undo_redo.cpp @@ -41,9 +41,13 @@ void UndoRedo::_discard_redo() { for (int i = current_action + 1; i < actions.size(); i++) { for (List<Operation>::Element *E = actions.write[i].do_ops.front(); E; E = E->next()) { if (E->get().type == Operation::TYPE_REFERENCE) { - Object *obj = ObjectDB::get_instance(E->get().object); - if (obj) { - memdelete(obj); + if (E->get().ref.is_valid()) { + E->get().ref.unref(); + } else { + Object *obj = ObjectDB::get_instance(E->get().object); + if (obj) { + memdelete(obj); + } } } } @@ -242,9 +246,13 @@ void UndoRedo::_pop_history_tail() { for (List<Operation>::Element *E = actions.write[0].undo_ops.front(); E; E = E->next()) { if (E->get().type == Operation::TYPE_REFERENCE) { - Object *obj = ObjectDB::get_instance(E->get().object); - if (obj) { - memdelete(obj); + if (E->get().ref.is_valid()) { + E->get().ref.unref(); + } else { + Object *obj = ObjectDB::get_instance(E->get().object); + if (obj) { + memdelete(obj); + } } } } |