Add locking to prim and avatar lists to fix enumeration errors

dsg
Robert Adams 2011-01-27 11:03:23 -08:00
parent cfab010b10
commit 8d87d9e42d
1 changed files with 19 additions and 13 deletions

View File

@ -55,7 +55,7 @@ public class PEScene : PhysicsScene
{ {
PECharacter actor = new PECharacter(avName, this, position, null, size, 0f, 0f, .5f, 1f, PECharacter actor = new PECharacter(avName, this, position, null, size, 0f, 0f, .5f, 1f,
1f, 1f, .5f, .5f); 1f, 1f, .5f, .5f);
m_avatars.Add(actor); lock (m_avatars) m_avatars.Add(actor);
return actor; return actor;
} }
@ -63,7 +63,7 @@ public class PEScene : PhysicsScene
{ {
try try
{ {
m_avatars.Remove((PECharacter)actor); lock (m_avatars) m_avatars.Remove((PECharacter)actor);
} }
catch (Exception e) catch (Exception e)
{ {
@ -75,7 +75,7 @@ public class PEScene : PhysicsScene
{ {
try try
{ {
m_prims.Remove((PEPrim)prim); lock (m_prims) m_prims.Remove((PEPrim)prim);
} }
catch (Exception e) catch (Exception e)
{ {
@ -92,7 +92,7 @@ public class PEScene : PhysicsScene
Vector3 size, Quaternion rotation, bool isPhysical) Vector3 size, Quaternion rotation, bool isPhysical)
{ {
PEPrim prim = new PEPrim(primName, this, position, size, rotation, null, pbs, isPhysical, null); PEPrim prim = new PEPrim(primName, this, position, size, rotation, null, pbs, isPhysical, null);
m_prims.Add(prim); lock (m_prims) m_prims.Add(prim);
return prim; return prim;
} }
@ -106,6 +106,8 @@ public class PEScene : PhysicsScene
if (SceneToPhysEngineSyncServer.IsActivePhysEngineScene2S()) if (SceneToPhysEngineSyncServer.IsActivePhysEngineScene2S())
{ {
// m_log.DebugFormat("[RPE]: Simulate. p={0}, a={1}", m_prims.Count, m_avatars.Count); // m_log.DebugFormat("[RPE]: Simulate. p={0}, a={1}", m_prims.Count, m_avatars.Count);
lock (m_prims)
{
foreach (PEPrim prim in m_prims) foreach (PEPrim prim in m_prims)
{ {
// if the values have changed and it was I who changed them, send an update // if the values have changed and it was I who changed them, send an update
@ -114,6 +116,9 @@ public class PEScene : PhysicsScene
SceneToPhysEngineSyncServer.RouteUpdate(prim); SceneToPhysEngineSyncServer.RouteUpdate(prim);
} }
} }
}
lock (m_avatars)
{
foreach (PECharacter actor in m_avatars) foreach (PECharacter actor in m_avatars)
{ {
// m_log.DebugFormat("[RPE]: Simulate. p={0}, a={1}", m_prims.Count, m_avatars.Count); // m_log.DebugFormat("[RPE]: Simulate. p={0}, a={1}", m_prims.Count, m_avatars.Count);
@ -124,6 +129,7 @@ public class PEScene : PhysicsScene
} }
} }
} }
}
return 60f; return 60f;
} }
/* /*