1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-06 17:25:19 +00:00

Prevent double counting and cyclical error when gathering Resources

This commit is contained in:
Sat
2025-11-30 04:18:52 -03:00
parent e6aa06d3de
commit 8b79e94fb6
2 changed files with 11 additions and 7 deletions

View File

@@ -1769,8 +1769,10 @@ void EditorNode::gather_resources(const Variant &p_variant, List<Ref<Resource>>
r_list.push_back(res); r_list.push_back(res);
} }
} }
if (Object::cast_to<Node>(v) == nullptr) {
gather_resources(v, r_list, p_subresources, p_allow_external); gather_resources(v, r_list, p_subresources, p_allow_external);
} }
}
return; return;
} }
@@ -1793,9 +1795,13 @@ void EditorNode::gather_resources(const Variant &p_variant, List<Ref<Resource>>
r_list.push_back(res_value); r_list.push_back(res_value);
} }
} }
if (Object::cast_to<Node>(kv.key) == nullptr) {
gather_resources(kv.key, r_list, p_subresources, p_allow_external); gather_resources(kv.key, r_list, p_subresources, p_allow_external);
}
if (Object::cast_to<Node>(kv.value) == nullptr) {
gather_resources(kv.value, r_list, p_subresources, p_allow_external); gather_resources(kv.value, r_list, p_subresources, p_allow_external);
} }
}
return; return;
} }
@@ -1809,12 +1815,10 @@ void EditorNode::gather_resources(const Variant &p_variant, List<Ref<Resource>>
Variant property_value = p_variant.get(E.name); Variant property_value = p_variant.get(E.name);
Variant::Type property_type = property_value.get_type(); Variant::Type property_type = property_value.get_type();
if (property_type == Variant::ARRAY || property_type == Variant::DICTIONARY) { if (property_type == Variant::ARRAY || property_type == Variant::DICTIONARY) {
gather_resources(property_value, r_list, p_subresources, p_allow_external); gather_resources(property_value, r_list, p_subresources, p_allow_external);
continue; continue;
} }
Ref<Resource> res = property_value; Ref<Resource> res = property_value;
if (res.is_null()) { if (res.is_null()) {
continue; continue;

View File

@@ -5186,9 +5186,9 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo
} else { } else {
undo_redo->add_undo_property(object, p_name, value); undo_redo->add_undo_property(object, p_name, value);
} }
// We'll use Editor Selection to get the currently edited Node.
Node *N = Object::cast_to<Node>(object); Node *N = Object::cast_to<Node>(object);
if (N && (type == Variant::OBJECT || type == Variant::ARRAY || type == Variant::DICTIONARY) && value != p_value) { bool double_counting = Object::cast_to<Node>(p_value) == N || Object::cast_to<Node>(value) == N;
if (N && !double_counting && (type == Variant::OBJECT || type == Variant::ARRAY || type == Variant::DICTIONARY) && value != p_value) {
undo_redo->add_do_method(EditorNode::get_singleton(), "update_node_reference", value, N, true); undo_redo->add_do_method(EditorNode::get_singleton(), "update_node_reference", value, N, true);
undo_redo->add_do_method(EditorNode::get_singleton(), "update_node_reference", p_value, N, false); undo_redo->add_do_method(EditorNode::get_singleton(), "update_node_reference", p_value, N, false);
// Perhaps an inefficient way of updating the resource count. // Perhaps an inefficient way of updating the resource count.