summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRafał Mikrut <mikrutrafal54@gmail.com>2020-10-25 17:16:29 +0100
committerRafał Mikrut <mikrutrafal@protonmail.com>2020-11-17 22:10:05 +0100
commit03f89a44812b0758d4d94407cc7500611f9e9c3d (patch)
tree8d6008767a33ce11a97bf6b49f59f6bcf008224d /core
parent8ac9a979562384a961f0c5ac4b72bda75f645e92 (diff)
Fix crash when printing leaked nodes
Diffstat (limited to 'core')
-rw-r--r--core/object/object.cpp37
1 files changed, 22 insertions, 15 deletions
diff --git a/core/object/object.cpp b/core/object/object.cpp
index 96a41d6852..a642647853 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -1841,9 +1841,13 @@ void postinitialize_handler(Object *p_object) {
void ObjectDB::debug_objects(DebugFunc p_func) {
spin_lock.lock();
- for (uint32_t i = 0; i < slot_count; i++) {
- uint32_t slot = object_slots[i].next_free;
- p_func(object_slots[slot].object);
+
+ for (uint32_t i = 0, count = slot_count; i < slot_max && count != 0; i++) {
+ if (object_slots[i].validator) {
+ p_func(object_slots[i].object);
+
+ count--;
+ }
}
spin_lock.unlock();
}
@@ -1955,20 +1959,23 @@ void ObjectDB::cleanup() {
MethodBind *resource_get_path = ClassDB::get_method("Resource", "get_path");
Callable::CallError call_error;
- for (uint32_t i = 0; i < slot_count; i++) {
- uint32_t slot = object_slots[i].next_free;
- Object *obj = object_slots[slot].object;
+ for (uint32_t i = 0, count = slot_count; i < slot_max && count != 0; i++) {
+ if (object_slots[i].validator) {
+ Object *obj = object_slots[i].object;
- String extra_info;
- if (obj->is_class("Node")) {
- extra_info = " - Node name: " + String(node_get_name->call(obj, nullptr, 0, call_error));
- }
- if (obj->is_class("Resource")) {
- extra_info = " - Resource path: " + String(resource_get_path->call(obj, nullptr, 0, call_error));
- }
+ String extra_info;
+ if (obj->is_class("Node")) {
+ extra_info = " - Node name: " + String(node_get_name->call(obj, nullptr, 0, call_error));
+ }
+ if (obj->is_class("Resource")) {
+ extra_info = " - Resource path: " + String(resource_get_path->call(obj, nullptr, 0, call_error));
+ }
+
+ uint64_t id = uint64_t(i) | (uint64_t(object_slots[i].validator) << OBJECTDB_VALIDATOR_BITS) | (object_slots[i].is_reference ? OBJECTDB_REFERENCE_BIT : 0);
+ print_line("Leaked instance: " + String(obj->get_class()) + ":" + itos(id) + extra_info);
- uint64_t id = uint64_t(slot) | (uint64_t(object_slots[slot].validator) << OBJECTDB_VALIDATOR_BITS) | (object_slots[slot].is_reference ? OBJECTDB_REFERENCE_BIT : 0);
- print_line("Leaked instance: " + String(obj->get_class()) + ":" + itos(id) + extra_info);
+ count--;
+ }
}
print_line("Hint: Leaked instances typically happen when nodes are removed from the scene tree (with `remove_child()`) but not freed (with `free()` or `queue_free()`).");
}