From 73e9b0be725a73a489b29f3fe2df236c897ef3b5 Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Wed, 17 Mar 2010 06:40:00 -0700 Subject: Inconsistent locking of ScenePresence array in SceneGraph. Fixed by eliminating option to return the actual list. Callers can now either request a copy of the array as a new List or ask the SceneGraph to call a delegate function on every ScenePresence. Iteration and locking of the ScenePresences now takes place only within the SceneGraph class. This patch also applies a fix to Combat/CombatModule.cs which had unlocked iteration of the ScenePresences and inconsistent try/catch around the use of those ScenePresences. --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 82 +++++++++------------- 1 file changed, 32 insertions(+), 50 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes/SceneObjectPart.cs') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index a2b98b9..0e21487 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -1197,15 +1197,14 @@ namespace OpenSim.Region.Framework.Scenes private void SendObjectPropertiesToClient(UUID AgentID) { - ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) { // Ugly reference :( - if (avatars[i].UUID == AgentID) + if (avatar.UUID == AgentID) { - m_parentGroup.GetProperties(avatars[i].ControllingClient); + m_parentGroup.GetProperties(avatar.ControllingClient); } - } + }); } // TODO: unused: @@ -1260,11 +1259,10 @@ namespace OpenSim.Region.Framework.Scenes /// public void AddFullUpdateToAllAvatars() { - ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) { - avatars[i].SceneViewer.QueuePartForUpdate(this); - } + avatar.SceneViewer.QueuePartForUpdate(this); + }); } public void AddFullUpdateToAvatar(ScenePresence presence) @@ -1285,11 +1283,10 @@ namespace OpenSim.Region.Framework.Scenes /// Terse updates public void AddTerseUpdateToAllAvatars() { - ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) { - avatars[i].SceneViewer.QueuePartForUpdate(this); - } + avatar.SceneViewer.QueuePartForUpdate(this); + }); } public void AddTerseUpdateToAvatar(ScenePresence presence) @@ -2121,17 +2118,13 @@ namespace OpenSim.Region.Framework.Scenes } else { - ScenePresence[] avlist = m_parentGroup.Scene.GetScenePresences(); - - for (int i = 0; i < avlist.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence av) { - ScenePresence av = avlist[i]; - if (av.LocalId == localId) { if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name)) { - bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); + bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data); //If it is 1, it is to accept ONLY collisions from this avatar if (found) { @@ -2153,7 +2146,7 @@ namespace OpenSim.Region.Framework.Scenes } else { - bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); + bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data); //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work if (!found) { @@ -2171,7 +2164,7 @@ namespace OpenSim.Region.Framework.Scenes } } - } + }); } } if (colliding.Count > 0) @@ -2257,17 +2250,13 @@ namespace OpenSim.Region.Framework.Scenes } else { - ScenePresence[] avlist = m_parentGroup.Scene.GetScenePresences(); - - for (int i = 0; i < avlist.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence av) { - ScenePresence av = avlist[i]; - if (av.LocalId == localId) { if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name)) { - bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); + bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data); //If it is 1, it is to accept ONLY collisions from this avatar if (found) { @@ -2289,7 +2278,7 @@ namespace OpenSim.Region.Framework.Scenes } else { - bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); + bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data); //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work if (!found) { @@ -2307,7 +2296,7 @@ namespace OpenSim.Region.Framework.Scenes } } - } + }); } } if (colliding.Count > 0) @@ -2388,17 +2377,13 @@ namespace OpenSim.Region.Framework.Scenes } else { - ScenePresence[] avlist = m_parentGroup.Scene.GetScenePresences(); - - for (int i = 0; i < avlist.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence av) { - ScenePresence av = avlist[i]; - if (av.LocalId == localId) { if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name)) { - bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); + bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data); //If it is 1, it is to accept ONLY collisions from this avatar if (found) { @@ -2420,7 +2405,7 @@ namespace OpenSim.Region.Framework.Scenes } else { - bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data); + bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data); //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work if (!found) { @@ -2438,7 +2423,7 @@ namespace OpenSim.Region.Framework.Scenes } } - } + }); } } @@ -2877,11 +2862,10 @@ namespace OpenSim.Region.Framework.Scenes /// public void SendFullUpdateToAllClients() { - ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) { - SendFullUpdate(avatars[i].ControllingClient, avatars[i].GenerateClientFlags(UUID)); - } + SendFullUpdate(avatar.ControllingClient, avatar.GenerateClientFlags(UUID)); + }); } /// @@ -2890,13 +2874,12 @@ namespace OpenSim.Region.Framework.Scenes /// public void SendFullUpdateToAllClientsExcept(UUID agentID) { - ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) { // Ugly reference :( - if (avatars[i].UUID != agentID) - SendFullUpdate(avatars[i].ControllingClient, avatars[i].GenerateClientFlags(UUID)); - } + if (avatar.UUID != agentID) + SendFullUpdate(avatar.ControllingClient, avatar.GenerateClientFlags(UUID)); + }); } /// @@ -3096,11 +3079,10 @@ namespace OpenSim.Region.Framework.Scenes /// public void SendTerseUpdateToAllClients() { - ScenePresence[] avatars = m_parentGroup.Scene.GetScenePresences(); - for (int i = 0; i < avatars.Length; i++) + m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar) { - SendTerseUpdateToClient(avatars[i].ControllingClient); - } + SendTerseUpdateToClient(avatar.ControllingClient); + }); } public void SetAttachmentPoint(uint AttachmentPoint) -- cgit v1.1