Fix crash on reimport scene with animations

This commit is contained in:
Hilderin 2024-08-02 16:50:22 -04:00
parent 3978628c6c
commit 769424388e
4 changed files with 35 additions and 0 deletions

View file

@ -4446,6 +4446,21 @@ void EditorNode::update_reimported_diff_data_for_additional_nodes(
}
}
void EditorNode::replace_history_reimported_nodes(Node *p_original_root_node, Node *p_new_root_node, Node *p_node) {
NodePath scene_path_to_node = p_original_root_node->get_path_to(p_node);
Node *new_node = p_new_root_node->get_node_or_null(scene_path_to_node);
if (new_node) {
editor_history.replace_object(p_node->get_instance_id(), new_node->get_instance_id());
} else {
editor_history.replace_object(p_node->get_instance_id(), ObjectID());
}
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *child = p_node->get_child(i);
replace_history_reimported_nodes(p_original_root_node, p_new_root_node, child);
}
}
void EditorNode::open_request(const String &p_path) {
if (!opening_prev) {
List<String>::Element *prev_scene_item = previous_scenes.find(p_path);
@ -6094,6 +6109,13 @@ void EditorNode::reload_instances_with_path_in_edited_scenes(const String &p_ins
owned_node->set_owner(nullptr);
}
// Replace the old nodes in the history with the new ones.
// Otherwise, the history will contain old nodes, and some could still be
// instantiated if used elsewhere, causing the "current edited item" to be
// linked to a node that will be destroyed later. This caused the editor to
// crash when reimporting scenes with animations when "Editable children" was enabled.
replace_history_reimported_nodes(original_node, instantiated_node, original_node);
// Delete all the remaining node children.
while (original_node->get_child_count()) {
Node *child = original_node->get_child(0);