Skip to content

Commit

Permalink
Merge pull request #36250 from Qrox/avoid-iterator-invalidation
Browse files Browse the repository at this point in the history
Avoid potential iterator invalidation in map::process_items
  • Loading branch information
ZhilkinSerg authored Dec 19, 2019
2 parents c6ee1cf + f145f4a commit b02b209
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4380,7 +4380,9 @@ void map::process_items( const bool active, map::map_process_func processor,
process_items_in_vehicles( *current_submap, pos.z, processor, signal );
}
}
for( const tripoint &abs_pos : submaps_with_active_items ) {
// Making a copy, in case the original variable gets modified during `process_items_in_submap`
const std::set<tripoint> submaps_with_active_items_copy = submaps_with_active_items;
for( const tripoint &abs_pos : submaps_with_active_items_copy ) {
const tripoint local_pos = abs_pos - abs_sub.xy();
submap *const current_submap = get_submap_at_grid( local_pos );
if( !active || !current_submap->active_items.empty() ) {
Expand Down

0 comments on commit b02b209

Please sign in to comment.