Thank you to Kiryu for a patch to fix an out of Sync

error in Scene. Affects 6 files and is Mantis#201
afrisby
Charles Krinke 2007-12-17 16:41:28 +00:00
parent e7170496be
commit a990c64698
6 changed files with 112 additions and 30 deletions

View File

@ -129,7 +129,7 @@ namespace OpenSim.Region.Environment.Scenes
internal void UpdateEntities() internal void UpdateEntities()
{ {
List<EntityBase> updateEntities = new List<EntityBase>(Entities.Values); List<EntityBase> updateEntities = GetEntities();
foreach (EntityBase entity in updateEntities) foreach (EntityBase entity in updateEntities)
{ {
@ -147,7 +147,7 @@ namespace OpenSim.Region.Environment.Scenes
internal void UpdateEntityMovement() internal void UpdateEntityMovement()
{ {
List<EntityBase> moveEntities = new List<EntityBase>(Entities.Values); List<EntityBase> moveEntities = GetEntities();
foreach (EntityBase entity in moveEntities) foreach (EntityBase entity in moveEntities)
{ {
@ -174,7 +174,10 @@ namespace OpenSim.Region.Environment.Scenes
if (!Entities.ContainsKey(sceneObject.UUID)) if (!Entities.ContainsKey(sceneObject.UUID))
{ {
// QuadTree.AddObject(sceneObject); // QuadTree.AddObject(sceneObject);
lock (Entities)
{
Entities.Add(sceneObject.UUID, sceneObject); Entities.Add(sceneObject.UUID, sceneObject);
}
m_numPrim++; m_numPrim++;
} }
} }
@ -188,7 +191,9 @@ namespace OpenSim.Region.Environment.Scenes
} }
public void RemovePrim(uint localID, LLUUID avatar_deleter) public void RemovePrim(uint localID, LLUUID avatar_deleter)
{ {
foreach (EntityBase obj in Entities.Values) List<EntityBase> EntityList = GetEntities();
foreach (EntityBase obj in EntityList)
{ {
if (obj is SceneObjectGroup) if (obj is SceneObjectGroup)
{ {
@ -310,7 +315,12 @@ namespace OpenSim.Region.Environment.Scenes
/// <returns></returns> /// <returns></returns>
public List<ScenePresence> GetScenePresences() public List<ScenePresence> GetScenePresences()
{ {
List<ScenePresence> result = new List<ScenePresence>(ScenePresences.Values); List<ScenePresence> result;
lock (ScenePresences)
{
result = new List<ScenePresence>(ScenePresences.Values);
}
return result; return result;
} }
@ -330,8 +340,9 @@ namespace OpenSim.Region.Environment.Scenes
public List<ScenePresence> GetScenePresences(FilterAvatarList filter) public List<ScenePresence> GetScenePresences(FilterAvatarList filter)
{ {
List<ScenePresence> result = new List<ScenePresence>(); List<ScenePresence> result = new List<ScenePresence>();
List<ScenePresence> ScenePresencesList = GetScenePresences();
foreach (ScenePresence avatar in ScenePresences.Values) foreach (ScenePresence avatar in ScenePresencesList)
{ {
if (filter(avatar)) if (filter(avatar))
{ {
@ -358,7 +369,9 @@ namespace OpenSim.Region.Environment.Scenes
private SceneObjectGroup GetGroupByPrim(uint localID) private SceneObjectGroup GetGroupByPrim(uint localID)
{ {
foreach (EntityBase ent in Entities.Values) List<EntityBase> EntityList = GetEntities();
foreach (EntityBase ent in EntityList)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
@ -371,7 +384,9 @@ namespace OpenSim.Region.Environment.Scenes
private SceneObjectGroup GetGroupByPrim(LLUUID fullID) private SceneObjectGroup GetGroupByPrim(LLUUID fullID)
{ {
foreach (EntityBase ent in Entities.Values) List<EntityBase> EntityList = GetEntities();
foreach (EntityBase ent in EntityList)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
@ -461,6 +476,18 @@ namespace OpenSim.Region.Environment.Scenes
return false; return false;
} }
public List<EntityBase> GetEntities()
{
List<EntityBase> result;
lock (Entities)
{
result = new List<EntityBase>(Entities.Values);
}
return result;
}
#endregion #endregion
#region Other Methods #region Other Methods
@ -484,7 +511,9 @@ namespace OpenSim.Region.Environment.Scenes
public void SendAllSceneObjectsToClient(ScenePresence presence) public void SendAllSceneObjectsToClient(ScenePresence presence)
{ {
foreach (EntityBase ent in Entities.Values) List<EntityBase> EntityList = GetEntities();
foreach (EntityBase ent in EntityList)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
@ -770,8 +799,10 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="childPrims"></param> /// <param name="childPrims"></param>
public void LinkObjects(uint parentPrim, List<uint> childPrims) public void LinkObjects(uint parentPrim, List<uint> childPrims)
{ {
List<EntityBase> EntityList = GetEntities();
SceneObjectGroup parenPrim = null; SceneObjectGroup parenPrim = null;
foreach (EntityBase ent in Entities.Values) foreach (EntityBase ent in EntityList)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
@ -788,7 +819,7 @@ namespace OpenSim.Region.Environment.Scenes
{ {
for (int i = 0; i < childPrims.Count; i++) for (int i = 0; i < childPrims.Count; i++)
{ {
foreach (EntityBase ent in Entities.Values) foreach (EntityBase ent in EntityList)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
@ -819,8 +850,10 @@ namespace OpenSim.Region.Environment.Scenes
// XXX I'm anticipating that building this dictionary once is more efficient than // XXX I'm anticipating that building this dictionary once is more efficient than
// repeated scanning of the Entity.Values for a large number of primIds. However, it might // repeated scanning of the Entity.Values for a large number of primIds. However, it might
// be more efficient yet to keep this dictionary permanently on hand. // be more efficient yet to keep this dictionary permanently on hand.
Dictionary<uint, SceneObjectGroup> sceneObjects = new Dictionary<uint, SceneObjectGroup>(); Dictionary<uint, SceneObjectGroup> sceneObjects = new Dictionary<uint, SceneObjectGroup>();
foreach (EntityBase ent in Entities.Values) List<EntityBase> EntitieList = GetEntities();
foreach (EntityBase ent in EntitieList)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
@ -863,8 +896,10 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="flags"></param> /// <param name="flags"></param>
public void DuplicateObject(uint originalPrim, LLVector3 offset, uint flags, LLUUID AgentID, LLUUID GroupID) public void DuplicateObject(uint originalPrim, LLVector3 offset, uint flags, LLUUID AgentID, LLUUID GroupID)
{ {
List<EntityBase> EntityList = GetEntities();
SceneObjectGroup originPrim = null; SceneObjectGroup originPrim = null;
foreach (EntityBase ent in Entities.Values) foreach (EntityBase ent in EntityList)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
@ -882,7 +917,10 @@ namespace OpenSim.Region.Environment.Scenes
{ {
SceneObjectGroup copy = originPrim.Copy(AgentID, GroupID); SceneObjectGroup copy = originPrim.Copy(AgentID, GroupID);
copy.AbsolutePosition = copy.AbsolutePosition + offset; copy.AbsolutePosition = copy.AbsolutePosition + offset;
lock (Entities)
{
Entities.Add(copy.UUID, copy); Entities.Add(copy.UUID, copy);
}
m_numPrim++; m_numPrim++;
copy.ScheduleGroupForFullUpdate(); copy.ScheduleGroupForFullUpdate();
} }

View File

@ -33,6 +33,7 @@ using OpenSim.Framework;
using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Communications.Cache;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
using OpenSim.Region.Physics.Manager; using OpenSim.Region.Physics.Manager;
using System.Collections.Generic;
namespace OpenSim.Region.Environment.Scenes namespace OpenSim.Region.Environment.Scenes
{ {
@ -342,7 +343,9 @@ namespace OpenSim.Region.Environment.Scenes
private SceneObjectGroup GetGroupByPrim(uint localID) private SceneObjectGroup GetGroupByPrim(uint localID)
{ {
foreach (EntityBase ent in Entities.Values) List<EntityBase> EntitieList = GetEntities();
foreach (EntityBase ent in EntitieList)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
@ -455,7 +458,10 @@ namespace OpenSim.Region.Environment.Scenes
{ {
EntityBase selectedEnt = null; EntityBase selectedEnt = null;
//MainLog.Instance.Verbose("CLIENT", "LocalID:" + Data.ObjectLocalID.ToString()); //MainLog.Instance.Verbose("CLIENT", "LocalID:" + Data.ObjectLocalID.ToString());
foreach (EntityBase ent in Entities.Values)
List<EntityBase> EntitieList = GetEntities();
foreach (EntityBase ent in EntitieList)
{ {
if (ent.LocalId == Data.ObjectLocalID) if (ent.LocalId == Data.ObjectLocalID)
{ {

View File

@ -97,7 +97,9 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="remoteClient"></param> /// <param name="remoteClient"></param>
public void SelectPrim(uint primLocalID, IClientAPI remoteClient) public void SelectPrim(uint primLocalID, IClientAPI remoteClient)
{ {
foreach (EntityBase ent in Entities.Values) List<EntityBase> EntitieList = GetEntities();
foreach (EntityBase ent in EntitieList)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
@ -119,7 +121,9 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="remoteClient"></param> /// <param name="remoteClient"></param>
public void DeselectPrim(uint primLocalID, IClientAPI remoteClient) public void DeselectPrim(uint primLocalID, IClientAPI remoteClient)
{ {
foreach (EntityBase ent in Entities.Values) List<EntityBase> EntitieList = GetEntities();
foreach (EntityBase ent in EntitieList)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
@ -137,7 +141,9 @@ namespace OpenSim.Region.Environment.Scenes
{ {
EventManager.TriggerObjectGrab(localID, offsetPos, remoteClient); EventManager.TriggerObjectGrab(localID, offsetPos, remoteClient);
foreach (EntityBase ent in Entities.Values) List<EntityBase> EntitieList = GetEntities();
foreach (EntityBase ent in EntitieList)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {

View File

@ -1615,7 +1615,9 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="message"></param> /// <param name="message"></param>
public void SendGeneralAlert(string message) public void SendGeneralAlert(string message)
{ {
foreach (ScenePresence presence in m_scenePresences.Values) List<ScenePresence> presenceList = GetScenePresences();
foreach (ScenePresence presence in presenceList)
{ {
presence.ControllingClient.SendAlertMessage(message); presence.ControllingClient.SendAlertMessage(message);
} }
@ -1776,7 +1778,9 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="modal"></param> /// <param name="modal"></param>
public void SendAlertToUser(string firstName, string lastName, string message, bool modal) public void SendAlertToUser(string firstName, string lastName, string message, bool modal)
{ {
foreach (ScenePresence presence in m_scenePresences.Values) List<ScenePresence> presenceList = GetScenePresences();
foreach (ScenePresence presence in presenceList)
{ {
if ((presence.Firstname == firstName) && (presence.Lastname == lastName)) if ((presence.Firstname == firstName) && (presence.Lastname == lastName))
{ {
@ -1821,7 +1825,9 @@ namespace OpenSim.Region.Environment.Scenes
/// </summary> /// </summary>
public void ForceClientUpdate() public void ForceClientUpdate()
{ {
foreach (EntityBase ent in Entities.Values) List<EntityBase> EntitieList = GetEntities();
foreach (EntityBase ent in EntitieList)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
@ -1838,7 +1844,10 @@ namespace OpenSim.Region.Environment.Scenes
public void HandleEditCommand(string[] cmdparams) public void HandleEditCommand(string[] cmdparams)
{ {
Console.WriteLine("Searching for Primitive: '" + cmdparams[0] + "'"); Console.WriteLine("Searching for Primitive: '" + cmdparams[0] + "'");
foreach (EntityBase ent in Entities.Values)
List<EntityBase> EntitieList = GetEntities();
foreach (EntityBase ent in EntitieList)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
@ -2017,7 +2026,8 @@ namespace OpenSim.Region.Environment.Scenes
if (!(m_scenePresences.Equals(null))) if (!(m_scenePresences.Equals(null)))
{ {
try { try {
foreach (ScenePresence presence in m_scenePresences.Values) List<ScenePresence> presenceList = GetScenePresences();
foreach (ScenePresence presence in presenceList)
{ {
action(presence); action(presence);
} }
@ -2033,7 +2043,14 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="action"></param> /// <param name="action"></param>
public void ForEachObject(Action<SceneObjectGroup> action) public void ForEachObject(Action<SceneObjectGroup> action)
{ {
foreach (SceneObjectGroup presence in m_sceneObjects.Values) List<SceneObjectGroup> presenceList;
lock (m_sceneObjects)
{
presenceList = new List<SceneObjectGroup>(m_sceneObjects.Values);
}
foreach (SceneObjectGroup presence in presenceList)
{ {
action(presence); action(presence);
} }
@ -2074,6 +2091,11 @@ namespace OpenSim.Region.Environment.Scenes
m_innerScene.ForEachClient(action); m_innerScene.ForEachClient(action);
} }
public List<EntityBase> GetEntities()
{
return m_innerScene.GetEntities();
}
#endregion #endregion
} }
} }

View File

@ -290,7 +290,9 @@ namespace OpenSim.Region.Environment.Scenes
{ {
ForEachCurrentScene(delegate(Scene scene) ForEachCurrentScene(delegate(Scene scene)
{ {
foreach (EntityBase entity in scene.Entities.Values) List<EntityBase> EntitieList = scene.GetEntities();
foreach (EntityBase entity in EntitieList)
{ {
if (entity is ScenePresence) if (entity is ScenePresence)
{ {
@ -315,7 +317,9 @@ namespace OpenSim.Region.Environment.Scenes
ForEachCurrentScene(delegate(Scene scene) ForEachCurrentScene(delegate(Scene scene)
{ {
foreach (EntityBase entity in scene.Entities.Values) List<EntityBase> EntitieList = scene.GetEntities();
foreach (EntityBase entity in EntitieList)
{ {
if (entity is ScenePresence) if (entity is ScenePresence)
{ {

View File

@ -108,7 +108,10 @@ namespace OpenSim.Region.Environment.Scenes
StreamWriter stream = new StreamWriter(file); StreamWriter stream = new StreamWriter(file);
int primCount = 0; int primCount = 0;
stream.WriteLine("<scene>\n"); stream.WriteLine("<scene>\n");
foreach (EntityBase ent in m_innerScene.Entities.Values)
List<EntityBase> EntityList = m_innerScene.GetEntities();
foreach (EntityBase ent in EntityList)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {
@ -170,7 +173,10 @@ namespace OpenSim.Region.Environment.Scenes
StreamWriter stream = new StreamWriter(file); StreamWriter stream = new StreamWriter(file);
int primCount = 0; int primCount = 0;
stream.WriteLine("<scene>\n"); stream.WriteLine("<scene>\n");
foreach (EntityBase ent in m_innerScene.Entities.Values)
List<EntityBase> EntityList = m_innerScene.GetEntities();
foreach (EntityBase ent in EntityList)
{ {
if (ent is SceneObjectGroup) if (ent is SceneObjectGroup)
{ {