Преглед изворни кода

Do not iterate over map when removing its values

(cherry picked from commit 29b288238108ca34b25a58a9376f418d61e55420)
Rafał Mikrut пре 4 година
родитељ
комит
927010e90f
1 измењених фајлова са 2 додато и 1 уклоњено
  1. 2 1
      scene/2d/tile_map.cpp

+ 2 - 1
scene/2d/tile_map.cpp

@@ -1049,8 +1049,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<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) {
 
+	Map<PosKey, Cell> temp_tile_map = tile_map;
+	for (Map<PosKey, Cell>::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);
 		}