summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormerumelu <merumelu@protonmail.com>2018-10-11 17:13:44 +0200
committermerumelu <merumelu@protonmail.com>2018-10-11 17:15:01 +0200
commit27596f6031ebdbcddc75ab36bb02ddc3f8813c2b (patch)
treefacf32893a0db2ca0e5763c026475e3bd90f999f
parent4c1a5d9cfe2da761bfe17d52126deabc1f1c1bd3 (diff)
TileSetEditor: Don't crash when adding invalid files
-rw-r--r--editor/plugins/tile_set_editor_plugin.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp
index 3de2284cea..9988d82fb8 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<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));