summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-10-12 12:09:54 +0200
committerGitHub <noreply@github.com>2018-10-12 12:09:54 +0200
commit43c28681add010b5daccbcfde3e3065d7be7b52c (patch)
tree6b8fc09f6c5369487a8024b69d144de671054171
parent5804efc6371fbfaec8fca6f237bd8478f2081086 (diff)
parent27596f6031ebdbcddc75ab36bb02ddc3f8813c2b (diff)
Merge pull request #22939 from merumelu/tileset-add-texture-fix
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));