From 372e4cfd49f492ba321315fb45da7156e3701833 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Fri, 16 Sep 2022 11:07:36 +0800 Subject: [PATCH] Fix crash open opening Add Metadata dialog --- editor/editor_inspector.cpp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 9e7314bf500..d4145643295 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -3983,13 +3983,7 @@ void EditorInspector::_check_meta_name(const String &p_name) { } else if (!p_name.is_valid_identifier()) { error = TTR("Metadata name must be a valid identifier."); } else if (object->has_meta(p_name)) { - Node *node = Object::cast_to(object); - if (node) { - error = vformat(TTR("Metadata with name \"%s\" already exists on \"%s\"."), p_name, node->get_name()); - } else { - // This should normally never be reached, but the error is set just in case. - error = vformat(TTR("Metadata with name \"%s\" already exists."), p_name, node->get_name()); - } + error = vformat(TTR("Metadata with name \"%s\" already exists."), p_name); } else if (p_name[0] == '_') { error = TTR("Names starting with _ are reserved for editor-only metadata."); } @@ -4009,14 +4003,6 @@ void EditorInspector::_show_add_meta_dialog() { if (!add_meta_dialog) { add_meta_dialog = memnew(ConfirmationDialog); - Node *node = Object::cast_to(object); - if (node) { - add_meta_dialog->set_title(vformat(TTR("Add Metadata Property for \"%s\""), node->get_name())); - } else { - // This should normally never be reached, but the title is set just in case. - add_meta_dialog->set_title(vformat(TTR("Add Metadata Property"), node->get_name())); - } - VBoxContainer *vbc = memnew(VBoxContainer); add_meta_dialog->add_child(vbc); HBoxContainer *hbc = memnew(HBoxContainer); @@ -4046,6 +4032,14 @@ void EditorInspector::_show_add_meta_dialog() { add_meta_name->connect("text_changed", callable_mp(this, &EditorInspector::_check_meta_name)); } + Node *node = Object::cast_to(object); + if (node) { + add_meta_dialog->set_title(vformat(TTR("Add Metadata Property for \"%s\""), node->get_name())); + } else { + // This should normally be reached when the object is derived from Resource. + add_meta_dialog->set_title(vformat(TTR("Add Metadata Property for \"%s\""), object->get_class())); + } + add_meta_dialog->popup_centered(); add_meta_name->set_text(""); _check_meta_name("");