Merge pull request #22939 from merumelu/tileset-add-texture-fix

TileSetEditor: Don't crash when adding invalid files
This commit is contained in:
Rémi Verschelde 2018-10-12 12:09:54 +02:00 committed by GitHub
commit 43c28681ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -569,6 +569,10 @@ void TileSetEditor::_on_textures_added(const PoolStringArray &p_paths) {
int invalid_count = 0;
for (int i = 0; i < p_paths.size(); i++) {
Ref<Texture> t = Ref<Texture>(ResourceLoader::load(p_paths[i]));
ERR_EXPLAIN("'" + p_paths[i] + "' is not a valid texture.");
ERR_CONTINUE(!t.is_valid());
if (texture_map.has(t->get_rid())) {
invalid_count++;
} else {
@ -577,9 +581,13 @@ void TileSetEditor::_on_textures_added(const PoolStringArray &p_paths) {
texture_list->set_item_metadata(texture_list->get_item_count() - 1, t->get_rid());
}
}
update_texture_list_icon();
texture_list->select(texture_list->get_item_count() - 1);
_on_texture_list_selected(texture_list->get_item_count() - 1);
if (texture_list->get_item_count() > 0) {
update_texture_list_icon();
texture_list->select(texture_list->get_item_count() - 1);
_on_texture_list_selected(texture_list->get_item_count() - 1);
}
if (invalid_count > 0) {
err_dialog->set_text(vformat(TTR("%s file(s) were not added because was already on the list."), String::num(invalid_count, 0)));
err_dialog->popup_centered(Size2(300, 60));