Index: ObjectManager.cs =================================================================== --- ObjectManager.cs (revision 2246) +++ ObjectManager.cs (working copy) @@ -2083,7 +2083,8 @@ { localID = kill.ObjectData[i].ID; - if (simulator.ObjectsPrimitives.Dictionary.ContainsKey(localID)) removePrims.Add(localID); + if (simulator.ObjectsPrimitives.Dictionary.ContainsKey(localID)) + removePrims.Add(localID); foreach (KeyValuePair prim in simulator.ObjectsPrimitives.Dictionary) { @@ -2096,6 +2097,16 @@ } } + //Do the actual removing outside of the loops but still inside the lock. + //This safely prevents the collection from being modified during a loop. + foreach (uint removeID in removePrims) + simulator.ObjectsPrimitives.Remove(removeID); + } + + lock (simulator.ObjectsAvatars.Dictionary) + { + List removeAvatars = new List(); + if (Client.Settings.AVATAR_TRACKING) { uint localID; @@ -2103,35 +2114,15 @@ { localID = kill.ObjectData[i].ID; - if (simulator.ObjectsAvatars.Dictionary.ContainsKey(localID)) removePrims.Add(localID); - - List rootPrims = new List(); - - foreach (KeyValuePair prim in simulator.ObjectsPrimitives.Dictionary) - { - if (prim.Value.ParentID == localID) - { - FireOnObjectKilled(simulator, prim.Key); - removePrims.Add(prim.Key); - rootPrims.Add(prim.Key); - } - } - - foreach (KeyValuePair prim in simulator.ObjectsPrimitives.Dictionary) - { - if (rootPrims.Contains(prim.Value.ParentID)) - { - FireOnObjectKilled(simulator, prim.Key); - removePrims.Add(prim.Key); - } - } + if (simulator.ObjectsAvatars.Dictionary.ContainsKey(localID)) + removeAvatars.Add(localID); } } //Do the actual removing outside of the loops but still inside the lock. //This safely prevents the collection from being modified during a loop. - foreach (uint removeID in removePrims) - simulator.ObjectsPrimitives.Remove(removeID); + foreach (uint removeID in removeAvatars) + simulator.ObjectsAvatars.Remove(removeID); } }