From caf4768117e60e444ae9c949afe97aedf5a3072b Mon Sep 17 00:00:00 2001 From: Kevin Granade Date: Fri, 22 Nov 2024 13:55:17 -0800 Subject: [PATCH] Stash mission ids and remove them after loop Erashing from a loop you are iterating over is no bueno --- src/mission.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mission.cpp b/src/mission.cpp index 08467b17dd7ec..9563ea1410d8f 100644 --- a/src/mission.cpp +++ b/src/mission.cpp @@ -259,6 +259,7 @@ bool mission::on_creature_fusion( Creature &fuser, Creature &fused ) return false; } bool mission_transfered = false; + std::vector mission_ids_to_remove; for( const int mission_id : mon_fused->mission_ids ) { const mission *const found_mission = mission::find( mission_id ); if( !found_mission ) { @@ -269,10 +270,13 @@ bool mission::on_creature_fusion( Creature &fuser, Creature &fused ) if( type->goal == MGOAL_KILL_MONSTER || type->goal == MGOAL_KILL_MONSTERS ) { // the fuser has to be killed now! mon_fuser->mission_ids.emplace( mission_id ); - mon_fused->mission_ids.erase( mission_id ); + mission_ids_to_remove.push_back( mission_id ); mission_transfered = true; } } + for( const int mission_id : mission_ids_to_remove ) { + mon_fused->mission_ids.erase( mission_id ); + } return mission_transfered; }