From 27596f6031ebdbcddc75ab36bb02ddc3f8813c2b Mon Sep 17 00:00:00 2001 From: merumelu Date: Thu, 11 Oct 2018 17:13:44 +0200 Subject: [PATCH] TileSetEditor: Don't crash when adding invalid files --- editor/plugins/tile_set_editor_plugin.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index 3de2284cea4..9988d82fb89 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -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 t = Ref(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));