stop KeyNotFoundException() being thrown in RemoveScenePresence if the agent isn't present in the presence dictionary

the code to do this was there but was being circumvented by newmap[agentID] before the check actually took place
0.7-release
Justin Clark-Casey (justincc) 2010-06-25 18:55:20 +01:00
parent 31b7279095
commit 24785e82a5
1 changed files with 7 additions and 6 deletions

View File

@ -599,7 +599,7 @@ namespace OpenSim.Region.Framework.Scenes
if (!Entities.Remove(agentID)) if (!Entities.Remove(agentID))
{ {
m_log.WarnFormat( m_log.WarnFormat(
"[SCENE] Tried to remove non-existent scene presence with agent ID {0} from scene Entities list", "[SCENE]: Tried to remove non-existent scene presence with agent ID {0} from scene Entities list",
agentID); agentID);
} }
@ -607,12 +607,13 @@ namespace OpenSim.Region.Framework.Scenes
{ {
Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap); Dictionary<UUID, ScenePresence> newmap = new Dictionary<UUID, ScenePresence>(m_scenePresenceMap);
List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray); List<ScenePresence> newlist = new List<ScenePresence>(m_scenePresenceArray);
// Remember the old presene reference from the dictionary
ScenePresence oldref = newmap[agentID];
// Remove the presence reference from the dictionary // Remove the presence reference from the dictionary
if (newmap.Remove(agentID)) if (newmap.ContainsKey(agentID))
{ {
ScenePresence oldref = newmap[agentID];
newmap.Remove(agentID);
// Find the index in the list where the old ref was stored and remove the reference // Find the index in the list where the old ref was stored and remove the reference
newlist.RemoveAt(newlist.IndexOf(oldref)); newlist.RemoveAt(newlist.IndexOf(oldref));
// Swap out the dictionary and list with new references // Swap out the dictionary and list with new references
@ -621,7 +622,7 @@ namespace OpenSim.Region.Framework.Scenes
} }
else else
{ {
m_log.WarnFormat("[SCENE] Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID); m_log.WarnFormat("[SCENE]: Tried to remove non-existent scene presence with agent ID {0} from scene ScenePresences list", agentID);
} }
} }
} }