diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 928a839cc1f..cf8f395821a 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -1024,7 +1024,9 @@ void TileMap::update_dirty_bitmask() { void TileMap::fix_invalid_tiles() { ERR_FAIL_COND_MSG(tile_set.is_null(), "Cannot fix invalid tiles if Tileset is not open."); - for (Map::Element *E = tile_map.front(); E; E = E->next()) { + + Map temp_tile_map = tile_map; + for (Map::Element *E = temp_tile_map.front(); E; E = E->next()) { if (!tile_set->has_tile(get_cell(E->key().x, E->key().y))) { set_cell(E->key().x, E->key().y, INVALID_CELL); }