summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-06-14 19:18:47 +0200
committerGitHub <noreply@github.com>2021-06-14 19:18:47 +0200
commitdedb314abbf15da30729cf3f2565eaa909daa296 (patch)
treeee93d2035bcf783aa54582668f5ff2a2f7a32004
parentec323f0ef435534c152de4ab83efb09813f1d7ae (diff)
parentd33185d201862c930664fa6418228ff22137cbb0 (diff)
Merge pull request #49586 from timothyqiu/iter-invalidate
Fix crash when using TileMap::fix_invalid_tiles
-rw-r--r--scene/2d/tile_map.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index e79dfb019c..e39c8841cd 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -711,12 +711,17 @@ Map<Vector2i, TileMapQuadrant> &TileMap::get_quadrant_map() {
void TileMap::fix_invalid_tiles() {
ERR_FAIL_COND_MSG(tile_set.is_null(), "Cannot fix invalid tiles if Tileset is not open.");
+
+ Set<Vector2i> coords;
for (Map<Vector2i, TileMapCell>::Element *E = tile_map.front(); E; E = E->next()) {
TileSetSource *source = *tile_set->get_source(E->get().source_id);
if (!source || !source->has_tile(E->get().get_atlas_coords()) || !source->has_alternative_tile(E->get().get_atlas_coords(), E->get().alternative_tile)) {
- set_cell(E->key(), -1, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE);
+ coords.insert(E->key());
}
}
+ for (Set<Vector2i>::Element *E = coords.front(); E; E = E->next()) {
+ set_cell(E->get(), -1, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE);
+ }
}
void TileMap::_recreate_quadrants() {