From 8b5d5dc2c4da38614dd73a6a53a476ce3170ed71 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Tue, 13 Jun 2023 11:31:53 +0800 Subject: [PATCH] Fix crash when opening a TileSet with invalid tiles --- editor/plugins/tiles/tiles_editor_plugin.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/editor/plugins/tiles/tiles_editor_plugin.cpp b/editor/plugins/tiles/tiles_editor_plugin.cpp index 0e9ff183556..b2ee3103ce2 100644 --- a/editor/plugins/tiles/tiles_editor_plugin.cpp +++ b/editor/plugins/tiles/tiles_editor_plugin.cpp @@ -108,9 +108,11 @@ void TilesEditorPlugin::_thread() { Vector2i coords = tile_map->get_cell_atlas_coords(0, cell); int alternative = tile_map->get_cell_alternative_tile(0, cell); - Vector2 center = world_pos - atlas_source->get_tile_data(coords, alternative)->get_texture_origin(); - encompassing_rect.expand_to(center - atlas_source->get_tile_texture_region(coords).size / 2); - encompassing_rect.expand_to(center + atlas_source->get_tile_texture_region(coords).size / 2); + if (atlas_source->has_tile(coords) && atlas_source->has_alternative_tile(coords, alternative)) { + Vector2 center = world_pos - atlas_source->get_tile_data(coords, alternative)->get_texture_origin(); + encompassing_rect.expand_to(center - atlas_source->get_tile_texture_region(coords).size / 2); + encompassing_rect.expand_to(center + atlas_source->get_tile_texture_region(coords).size / 2); + } } }