summaryrefslogtreecommitdiff
path: root/core/object
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-11-28 10:37:12 +0100
committerGitHub <noreply@github.com>2020-11-28 10:37:12 +0100
commit3b4fad435c2856398f87b6f010013ce1a114b31b (patch)
treea06f323f575f855b0b14020256ccbb9e81cbeb09 /core/object
parent53b23c6bdcba2b7d9ee36682f026c9ebf67ded66 (diff)
parent03f89a44812b0758d4d94407cc7500611f9e9c3d (diff)
Merge pull request #43061 from qarmin/crash_when_prining_nodes
Fix crash when printing leaked nodes
Diffstat (limited to 'core/object')
-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()`).");
}