diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index b4019554b..e450f47a2 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -147,9 +147,14 @@ void FGAIManager::update(double dt) { if ((*ai_list_itr)->getDie()) { freeID((*ai_list_itr)->getID()); delete (*ai_list_itr); - ai_list.erase(ai_list_itr); - --ai_list_itr; --numObjects; + if ( ai_list_itr == ai_list.begin() ) { + ai_list.erase(ai_list_itr); + ai_list_itr = ai_list.begin(); + continue; + } else { + ai_list.erase(ai_list_itr--); + } } else { fetchUserState(); if ((*ai_list_itr)->isa(FGAIBase::otThermal)) {