From 1ac35c38be336207ac7a8df7a769efe6e0a09ba4 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Fri, 30 Dec 2022 14:15:30 +0800 Subject: [PATCH] Fix heap-use-after-free when using TileMap editor --- editor/plugins/tiles/tile_map_editor.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/editor/plugins/tiles/tile_map_editor.cpp b/editor/plugins/tiles/tile_map_editor.cpp index 5a1f214933d..414c3a2759c 100644 --- a/editor/plugins/tiles/tile_map_editor.cpp +++ b/editor/plugins/tiles/tile_map_editor.cpp @@ -1488,13 +1488,15 @@ void TileMapEditorTilesPlugin::_update_fix_selected_and_hovered() { } // Selection if needed. - for (RBSet::Element *E = tile_set_selection.front(); E; E = E->next()) { + for (RBSet::Element *E = tile_set_selection.front(); E;) { + RBSet::Element *N = E->next(); const TileMapCell *selected = &(E->get()); if (!tile_set->has_source(selected->source_id) || !tile_set->get_source(selected->source_id)->has_tile(selected->get_atlas_coords()) || !tile_set->get_source(selected->source_id)->has_alternative_tile(selected->get_atlas_coords(), selected->alternative_tile)) { tile_set_selection.erase(E); } + E = N; } if (!tile_map_selection.is_empty()) {