Merge pull request #39203 from Xrayez/fix-no-lang-crash

Prevent crash attaching a script with no languages registered
This commit is contained in:
Rémi Verschelde 2020-06-03 11:08:35 +02:00 committed by GitHub
commit cec49bd194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -2557,6 +2557,11 @@ void SceneTreeDock::_focus_node() {
}
void SceneTreeDock::attach_script_to_selected(bool p_extend) {
if (ScriptServer::get_language_count() == 0) {
EditorNode::get_singleton()->show_warning(TTR("Cannot attach a script: there are no languages registered.\nThis is probably because this editor was built with all language modules disabled."));
return;
}
if (!profile_allow_script_editing) {
return;
}

View File

@ -783,7 +783,7 @@ ScriptCreateDialog::ScriptCreateDialog() {
gc->add_child(memnew(Label(TTR("Language:"))));
gc->add_child(language_menu);
default_language = 0;
default_language = -1;
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
String lang = ScriptServer::get_language(i)->get_name();
language_menu->add_item(lang);
@ -791,8 +791,9 @@ ScriptCreateDialog::ScriptCreateDialog() {
default_language = i;
}
}
language_menu->select(default_language);
if (default_language >= 0) {
language_menu->select(default_language);
}
current_language = default_language;
language_menu->connect("item_selected", callable_mp(this, &ScriptCreateDialog::_lang_changed));