Merge pull request #50782 from timothyqiu/undoredo-ref

Fix UndoRedo crash when clearing history
This commit is contained in:
Rémi Verschelde 2021-07-23 19:27:51 +02:00 committed by GitHub
commit e0d48f87f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
}
}
}
}