From c42fe6c159d49535888937c3f219e028eb755efa Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Tue, 14 Aug 2012 21:44:06 +0100 Subject: Prevent race conditions when one thread removes an NPC SP before another thread has retreived it after checking whether the NPC exists. --- .../Region/OptionalModules/World/NPC/NPCModule.cs | 64 ++++++++++------------ 1 file changed, 30 insertions(+), 34 deletions(-) (limited to 'OpenSim/Region/OptionalModules/World') diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 1e85fb4..3f25bcf 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -176,16 +176,17 @@ namespace OpenSim.Region.OptionalModules.World.NPC if (m_avatars.ContainsKey(agentID)) { ScenePresence sp; - scene.TryGetScenePresence(agentID, out sp); - - m_log.DebugFormat( - "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", - sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget); - - sp.MoveToTarget(pos, noFly, landAtTarget); - sp.SetAlwaysRun = running; - - return true; + if (scene.TryGetScenePresence(agentID, out sp)) + { + m_log.DebugFormat( + "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", + sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget); + + sp.MoveToTarget(pos, noFly, landAtTarget); + sp.SetAlwaysRun = running; + + return true; + } } } @@ -199,12 +200,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC if (m_avatars.ContainsKey(agentID)) { ScenePresence sp; - scene.TryGetScenePresence(agentID, out sp); - - sp.Velocity = Vector3.Zero; - sp.ResetMoveToTarget(); + if (scene.TryGetScenePresence(agentID, out sp)) + { + sp.Velocity = Vector3.Zero; + sp.ResetMoveToTarget(); - return true; + return true; + } } } @@ -222,9 +224,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC { if (m_avatars.ContainsKey(agentID)) { - ScenePresence sp; - scene.TryGetScenePresence(agentID, out sp); - m_avatars[agentID].Say(channel, text); return true; @@ -240,9 +239,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC { if (m_avatars.ContainsKey(agentID)) { - ScenePresence sp; - scene.TryGetScenePresence(agentID, out sp); - m_avatars[agentID].Shout(channel, text); return true; @@ -259,11 +255,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC if (m_avatars.ContainsKey(agentID)) { ScenePresence sp; - scene.TryGetScenePresence(agentID, out sp); - sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero); -// sp.HandleAgentSit(m_avatars[agentID], agentID); - - return true; + if (scene.TryGetScenePresence(agentID, out sp)) + { + sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero); + // sp.HandleAgentSit(m_avatars[agentID], agentID); + + return true; + } } } @@ -276,9 +274,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC { if (m_avatars.ContainsKey(agentID)) { - ScenePresence sp; - scene.TryGetScenePresence(agentID, out sp); - m_avatars[agentID].Whisper(channel, text); return true; @@ -295,10 +290,12 @@ namespace OpenSim.Region.OptionalModules.World.NPC if (m_avatars.ContainsKey(agentID)) { ScenePresence sp; - scene.TryGetScenePresence(agentID, out sp); - sp.StandUp(); + if (scene.TryGetScenePresence(agentID, out sp)) + { + sp.StandUp(); - return true; + return true; + } } } @@ -311,6 +308,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC { if (m_avatars.ContainsKey(agentID)) return m_avatars[agentID].Touch(objectID); + return false; } } @@ -321,9 +319,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC { NPCAvatar av; if (m_avatars.TryGetValue(agentID, out av)) - { return av.OwnerID; - } } return UUID.Zero; -- cgit v1.1