Core: Add hints to run with --verbose when leaking nodes/resources at exit
(cherry picked from commit 2b5545270a
)
This commit is contained in:
parent
2652a2d184
commit
ebb30ac45a
2 changed files with 14 additions and 12 deletions
|
@ -2132,7 +2132,7 @@ void ObjectDB::cleanup() {
|
||||||
rw_lock->write_lock();
|
rw_lock->write_lock();
|
||||||
if (instances.size()) {
|
if (instances.size()) {
|
||||||
|
|
||||||
WARN_PRINT("ObjectDB Instances still exist!");
|
WARN_PRINT("ObjectDB instances leaked at exit (run with --verbose for details).");
|
||||||
if (OS::get_singleton()->is_stdout_verbose()) {
|
if (OS::get_singleton()->is_stdout_verbose()) {
|
||||||
const ObjectID *K = NULL;
|
const ObjectID *K = NULL;
|
||||||
while ((K = instances.next(K))) {
|
while ((K = instances.next(K))) {
|
||||||
|
@ -2141,9 +2141,10 @@ void ObjectDB::cleanup() {
|
||||||
if (instances[*K]->is_class("Node"))
|
if (instances[*K]->is_class("Node"))
|
||||||
node_name = " - Node name: " + String(instances[*K]->call("get_name"));
|
node_name = " - Node name: " + String(instances[*K]->call("get_name"));
|
||||||
if (instances[*K]->is_class("Resource"))
|
if (instances[*K]->is_class("Resource"))
|
||||||
node_name = " - Resource name: " + String(instances[*K]->call("get_name")) + " Path: " + String(instances[*K]->call("get_path"));
|
node_name = " - Resource path: " + String(instances[*K]->call("get_path"));
|
||||||
print_line("Leaked instance: " + String(instances[*K]->get_class()) + ":" + itos(*K) + node_name);
|
print_line("Leaked instance: " + String(instances[*K]->get_class()) + ":" + itos(*K) + node_name);
|
||||||
}
|
}
|
||||||
|
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()`).");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
instances.clear();
|
instances.clear();
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "core/core_string_names.h"
|
#include "core/core_string_names.h"
|
||||||
#include "core/io/resource_loader.h"
|
#include "core/io/resource_loader.h"
|
||||||
#include "core/os/file_access.h"
|
#include "core/os/file_access.h"
|
||||||
|
#include "core/os/os.h"
|
||||||
#include "core/script_language.h"
|
#include "core/script_language.h"
|
||||||
#include "scene/main/node.h" //only so casting works
|
#include "scene/main/node.h" //only so casting works
|
||||||
|
|
||||||
|
@ -472,21 +473,22 @@ void ResourceCache::setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceCache::clear() {
|
void ResourceCache::clear() {
|
||||||
if (resources.size())
|
if (resources.size()) {
|
||||||
ERR_PRINT("Resources Still in use at Exit!");
|
ERR_PRINT("Resources still in use at exit (run with --verbose for details).");
|
||||||
|
if (OS::get_singleton()->is_stdout_verbose()) {
|
||||||
|
const String *K = nullptr;
|
||||||
|
while ((K = resources.next(K))) {
|
||||||
|
Resource *r = resources[*K];
|
||||||
|
print_line(vformat("Resource still in use: %s (%s)", *K, r->get_class()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
resources.clear();
|
resources.clear();
|
||||||
memdelete(lock);
|
memdelete(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceCache::reload_externals() {
|
void ResourceCache::reload_externals() {
|
||||||
|
|
||||||
/*
|
|
||||||
const String *K=NULL;
|
|
||||||
while ((K=resources.next(K))) {
|
|
||||||
resources[*K]->reload_external_data();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ResourceCache::has(const String &p_path) {
|
bool ResourceCache::has(const String &p_path) {
|
||||||
|
@ -573,6 +575,5 @@ void ResourceCache::dump(const char *p_file, bool p_short) {
|
||||||
}
|
}
|
||||||
|
|
||||||
lock->read_unlock();
|
lock->read_unlock();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue