diff --git a/scene/2d/tile_map_layer.cpp b/scene/2d/tile_map_layer.cpp index df79b3fee658..bba0f84be7bf 100644 --- a/scene/2d/tile_map_layer.cpp +++ b/scene/2d/tile_map_layer.cpp @@ -2111,6 +2111,8 @@ void TileMapLayer::notify_tile_map_change(DirtyFlags p_what) { } void TileMapLayer::internal_update() { + MutexLock lock(dirty.mutex); + // Find TileData that need a runtime modification. // This may add cells to the dirty list is a runtime modification has been notified. _build_runtime_update_tile_data(); @@ -2187,6 +2189,7 @@ void TileMapLayer::set_cell(const Vector2i &p_coords, int p_source_id, const Vec c.alternative_tile = alternative_tile; // Make the given cell dirty. + MutexLock lock(dirty.mutex); if (!E->value.dirty_list_element.in_list()) { dirty.cell_list.add(&(E->value.dirty_list_element)); } @@ -2939,4 +2942,4 @@ TerrainConstraint::TerrainConstraint(Ref p_tile_set, const Vector2i &p_ } } terrain = p_terrain; -} \ No newline at end of file +} diff --git a/scene/2d/tile_map_layer.h b/scene/2d/tile_map_layer.h index 2cc57f50d1b6..aa4232da229a 100644 --- a/scene/2d/tile_map_layer.h +++ b/scene/2d/tile_map_layer.h @@ -262,6 +262,7 @@ class TileMapLayer : public Node2D { // Dirty flag. Allows knowing what was modified since the last update. struct { + Mutex mutex; bool flags[DIRTY_FLAGS_MAX] = { false }; SelfList::List cell_list; } dirty;