Skip to content

Commit

Permalink
Merge pull request #79851 from timothyqiu/null-tileset
Browse files Browse the repository at this point in the history
Fix crash when executing `TileMap.fix_invalid_tiles`
  • Loading branch information
YuriSizov committed Jul 24, 2023
2 parents 21524e2 + a7ab7e4 commit f618701
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion scene/2d/tile_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2273,9 +2273,12 @@ void TileMapLayer::force_update() {
}

void TileMapLayer::fix_invalid_tiles() {
Ref<TileSet> tileset = tile_map_node->get_tileset();
ERR_FAIL_COND_MSG(tileset.is_null(), "Cannot call fix_invalid_tiles() on a TileMap without a valid TileSet.");

RBSet<Vector2i> coords;
for (const KeyValue<Vector2i, TileMapCell> &E : tile_map) {
TileSetSource *source = *(tile_map_node->get_tileset())->get_source(E.value.source_id);
TileSetSource *source = *tileset->get_source(E.value.source_id);
if (!source || !source->has_tile(E.value.get_atlas_coords()) || !source->has_alternative_tile(E.value.get_atlas_coords(), E.value.alternative_tile)) {
coords.insert(E.key);
}
Expand Down

0 comments on commit f618701

Please sign in to comment.