diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index b834619d2c..9232db9e0a 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -398,27 +398,31 @@ namespace OpenSim.Region.OptionalModules.World.NPC public bool DeleteNPC(UUID agentID, Scene scene) { + bool doRemove = false; + NPCAvatar av; lock (m_avatars) { - NPCAvatar av; if (m_avatars.TryGetValue(agentID, out av)) { /* m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove", agentID, av.Name); */ - - scene.CloseAgent(agentID, false); - - m_avatars.Remove(agentID); - - /* - m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", - agentID, av.Name); - */ - return true; + doRemove = true; } } + + if (doRemove) + { + scene.CloseAgent(agentID, false); + lock (m_avatars) + { + m_avatars.Remove(agentID); + } + m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", + agentID, av.Name); + return true; + } /* m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove", agentID); @@ -457,4 +461,4 @@ namespace OpenSim.Region.OptionalModules.World.NPC av.OwnerID == callerID || av.AgentId == callerID; } } -} \ No newline at end of file +}