From 44f0cadad8f51e33d6af49d7ef3b3e175bd5b8b2 Mon Sep 17 00:00:00 2001
From: maxim_productengine <mnikolenko@productengine.com>
Date: Thu, 27 Feb 2020 15:30:09 +0200
Subject: SL-12739 FIXED [EEP] Viewer is crashed after clicking the "Forget"
 button on the Experience Profile after the llSetAgentEnvironment was used

---
 indra/newview/llenvironment.cpp | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/indra/newview/llenvironment.cpp b/indra/newview/llenvironment.cpp
index 8f778711ce..b8c5648cca 100644
--- a/indra/newview/llenvironment.cpp
+++ b/indra/newview/llenvironment.cpp
@@ -397,8 +397,8 @@ namespace
 
         void removeInjection(const std::string keyname, LLUUID experience, LLSettingsBase::Seconds transition)
         {
-            auto it = mInjections.begin();
-            while (it != mInjections.end())
+            injections_t injections_buf;
+            for (auto it = mInjections.begin(); it != mInjections.end(); it++)
             {
                 if ((keyname.empty() || ((*it)->mKeyName == keyname)) &&
                     (experience.isNull() || (experience == (*it)->mExperience)))
@@ -406,13 +406,16 @@ namespace
                     if (transition != LLEnvironment::TRANSITION_INSTANT)
                     {
                         typename Injection::ptr_t injection = std::make_shared<Injection>(transition, keyname, (*it)->mLastValue, false, LLUUID::null);
-                        mInjections.push_front(injection); // push them in at the front so we don't check them again.
+                        injections_buf.push_front(injection);
                     }
-                    mInjections.erase(it++);
                 }
                 else
-                    ++it;
+                {
+                    injections_buf.push_front(*it);
+                }
             }
+            mInjections.clear();
+            mInjections = injections_buf;
 
             for (auto itexp = mOverrideExps.begin(); itexp != mOverrideExps.end();)
             {
-- 
cgit v1.2.3