Fix UndoRedo::create_action()
invalid memory usage
This commit is contained in:
parent
73f92a6e4d
commit
b00b7f9b7c
2 changed files with 19 additions and 27 deletions
|
@ -34,6 +34,20 @@
|
||||||
#include "core/os/os.h"
|
#include "core/os/os.h"
|
||||||
#include "core/templates/local_vector.h"
|
#include "core/templates/local_vector.h"
|
||||||
|
|
||||||
|
void UndoRedo::Operation::delete_reference() {
|
||||||
|
if (type != Operation::TYPE_REFERENCE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ref.is_valid()) {
|
||||||
|
ref.unref();
|
||||||
|
} else {
|
||||||
|
Object *obj = ObjectDB::get_instance(object);
|
||||||
|
if (obj) {
|
||||||
|
memdelete(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UndoRedo::_discard_redo() {
|
void UndoRedo::_discard_redo() {
|
||||||
if (current_action == actions.size() - 1) {
|
if (current_action == actions.size() - 1) {
|
||||||
return;
|
return;
|
||||||
|
@ -41,16 +55,7 @@ void UndoRedo::_discard_redo() {
|
||||||
|
|
||||||
for (int i = current_action + 1; i < actions.size(); i++) {
|
for (int i = current_action + 1; i < actions.size(); i++) {
|
||||||
for (Operation &E : actions.write[i].do_ops) {
|
for (Operation &E : actions.write[i].do_ops) {
|
||||||
if (E.type == Operation::TYPE_REFERENCE) {
|
E.delete_reference();
|
||||||
if (E.ref.is_valid()) {
|
|
||||||
E.ref.unref();
|
|
||||||
} else {
|
|
||||||
Object *obj = ObjectDB::get_instance(E.object);
|
|
||||||
if (obj) {
|
|
||||||
memdelete(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//ERASE do data
|
//ERASE do data
|
||||||
}
|
}
|
||||||
|
@ -97,13 +102,7 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode) {
|
||||||
for (unsigned int i = 0; i < to_remove.size(); i++) {
|
for (unsigned int i = 0; i < to_remove.size(); i++) {
|
||||||
List<Operation>::Element *E = to_remove[i];
|
List<Operation>::Element *E = to_remove[i];
|
||||||
// Delete all object references
|
// Delete all object references
|
||||||
if (E->get().type == Operation::TYPE_REFERENCE) {
|
E->get().delete_reference();
|
||||||
Object *obj = ObjectDB::get_instance(E->get().object);
|
|
||||||
|
|
||||||
if (obj) {
|
|
||||||
memdelete(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
E->erase();
|
E->erase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,16 +269,7 @@ void UndoRedo::_pop_history_tail() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Operation &E : actions.write[0].undo_ops) {
|
for (Operation &E : actions.write[0].undo_ops) {
|
||||||
if (E.type == Operation::TYPE_REFERENCE) {
|
E.delete_reference();
|
||||||
if (E.ref.is_valid()) {
|
|
||||||
E.ref.unref();
|
|
||||||
} else {
|
|
||||||
Object *obj = ObjectDB::get_instance(E.object);
|
|
||||||
if (obj) {
|
|
||||||
memdelete(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.remove_at(0);
|
actions.remove_at(0);
|
||||||
|
|
|
@ -66,6 +66,8 @@ private:
|
||||||
ObjectID object;
|
ObjectID object;
|
||||||
StringName name;
|
StringName name;
|
||||||
Variant args[VARIANT_ARG_MAX];
|
Variant args[VARIANT_ARG_MAX];
|
||||||
|
|
||||||
|
void delete_reference();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Action {
|
struct Action {
|
||||||
|
|
Loading…
Add table
Reference in a new issue