From c1c5b0a4357a8f84fa29aa199b98af54d4b25537 Mon Sep 17 00:00:00 2001 From: kobewi Date: Wed, 21 Jun 2023 00:01:59 +0200 Subject: [PATCH] Update indices after removing custom data layers --- scene/resources/tile_set.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 5f191214472..96096afeb49 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -1063,12 +1063,16 @@ void TileSet::move_custom_data_layer(int p_from_index, int p_to_pos) { void TileSet::remove_custom_data_layer(int p_index) { ERR_FAIL_INDEX(p_index, custom_data_layers.size()); custom_data_layers.remove_at(p_index); - for (KeyValue E : custom_data_layers_by_name) { + + String to_erase; + for (KeyValue &E : custom_data_layers_by_name) { if (E.value == p_index) { - custom_data_layers_by_name.erase(E.key); - break; + to_erase = E.key; + } else if (E.value > p_index) { + E.value--; } } + custom_data_layers_by_name.erase(to_erase); for (KeyValue> source : sources) { source.value->remove_custom_data_layer(p_index);