From 7404873b6633e152a2b91d7ffb6218acbe02bb18 Mon Sep 17 00:00:00 2001 From: Caleb Cassady Date: Mon, 10 Feb 2025 22:18:10 -0500 Subject: [PATCH] Fix TileMapLayer bug where dirty cells could be marked twice When using runtime data in a TileMapLayer, calling notify_runtime_tile_update can cause error messages to be printed to the console if the same cell has been set or erased in the same frame. This could be partially worked around by using call_deferred on notify_runtime_tile_update, but the problem could re-emerge if those updates were being made in coroutines. This commit addresses the issue by adding an additional check to the dirty cell marking of the TileMapLayer when notify_runtime_tile_update is called. This check ensures that the cell has not already been added to the dirty cell list, preventing the condition that causes the error message. --- scene/2d/tile_map_layer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scene/2d/tile_map_layer.cpp b/scene/2d/tile_map_layer.cpp index 56896233ec..2bb190b126 100644 --- a/scene/2d/tile_map_layer.cpp +++ b/scene/2d/tile_map_layer.cpp @@ -1413,7 +1413,7 @@ void TileMapLayer::_build_runtime_update_tile_data_for_cell(CellData &r_cell_dat tile_map_node->GDVIRTUAL_CALL(_tile_data_runtime_update, layer_index_in_tile_map_node, r_cell_data.coords, tile_data_runtime_use); - if (p_auto_add_to_dirty_list) { + if (p_auto_add_to_dirty_list && !r_cell_data.dirty_list_element.in_list()) { dirty.cell_list.add(&r_cell_data.dirty_list_element); } } @@ -1428,7 +1428,7 @@ void TileMapLayer::_build_runtime_update_tile_data_for_cell(CellData &r_cell_dat GDVIRTUAL_CALL(_tile_data_runtime_update, r_cell_data.coords, tile_data_runtime_use); - if (p_auto_add_to_dirty_list) { + if (p_auto_add_to_dirty_list && !r_cell_data.dirty_list_element.in_list()) { dirty.cell_list.add(&r_cell_data.dirty_list_element); } }