summaryrefslogtreecommitdiffstats
path: root/scene/main/node.cpp
diff options
context:
space:
mode:
authorHugo Locurcio <hugo.locurcio@hugo.pro>2023-06-05 19:57:33 +0200
committerHugo Locurcio <hugo.locurcio@hugo.pro>2023-06-07 16:06:53 +0200
commitbd468cdec7101b5403f0edf0b0dd25f2e252d8c7 (patch)
tree223123806be03c30a0eed53406700a8353e4ceb2 /scene/main/node.cpp
parent0f76ff2115ae56e6638e1e2bdb8851d470e6e0e3 (diff)
downloadredot-engine-bd468cdec7101b5403f0edf0b0dd25f2e252d8c7.tar.gz
Display the node path or name in Node thread guard errors
This makes it easier to diagnose which node is the source of the issue.
Diffstat (limited to 'scene/main/node.cpp')
-rw-r--r--scene/main/node.cpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index ad7e445b5c..094c3f0c94 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -1167,6 +1167,20 @@ void Node::set_name(const String &p_name) {
}
}
+// Returns a clear description of this node depending on what is available. Useful for error messages.
+String Node::get_description() const {
+ String description;
+ if (is_inside_tree()) {
+ description = get_path();
+ } else {
+ description = get_name();
+ if (description.is_empty()) {
+ description = get_class();
+ }
+ }
+ return description;
+}
+
static SafeRefCount node_hrcr_count;
void Node::init_node_hrcr() {
@@ -1596,17 +1610,7 @@ Node *Node::get_node(const NodePath &p_path) const {
Node *node = get_node_or_null(p_path);
if (unlikely(!node)) {
- // Try to get a clear description of this node in the error message.
- String desc;
- if (is_inside_tree()) {
- desc = get_path();
- } else {
- desc = get_name();
- if (desc.is_empty()) {
- desc = get_class();
- }
- }
-
+ const String desc = get_description();
if (p_path.is_absolute()) {
ERR_FAIL_V_MSG(nullptr,
vformat(R"(Node not found: "%s" (absolute path attempted from "%s").)", p_path, desc));