Make SP.Attachments available as sp.GetAttachments() instead.

The approach here, as in other parts of OpenSim, is to return a copy of the list rather than the attachments list itself
This prevents callers from forgetting to lock the list when they read it, as was happening in various parts of the codebase.
It also improves liveness.
This might improve attachment anomolies when performing region crossings.
This commit is contained in:
Justin Clark-Casey (justincc)
2011-08-31 16:29:51 +01:00
parent 2acfff9f6d
commit 32444d98cb
7 changed files with 101 additions and 75 deletions

View File

@@ -136,10 +136,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
public void SaveChangedAttachments(IScenePresence sp)
{
// Need to copy this list because DetachToInventoryPrep mods it
List<SceneObjectGroup> attachments = new List<SceneObjectGroup>(sp.Attachments);
foreach (SceneObjectGroup grp in attachments)
foreach (SceneObjectGroup grp in sp.GetAttachments())
{
if (grp.HasGroupChanged) // Resizer scripts?
{
@@ -273,14 +270,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
// Remove any previous attachments
UUID itemID = UUID.Zero;
foreach (SceneObjectGroup grp in sp.Attachments)
{
if (grp.AttachmentPoint == attachmentPt)
{
itemID = grp.GetFromItemID();
break;
}
}
List<SceneObjectGroup> attachments = sp.GetAttachments(attachmentPt);
// At the moment we can only deal with a single attachment
if (attachments.Count != 0)
itemID = attachments[0].GetFromItemID();
if (itemID != UUID.Zero)
DetachSingleAttachmentToInv(itemID, sp);

View File

@@ -106,7 +106,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
// Check status on scene presence
Assert.That(m_presence.HasAttachments(), Is.True);
List<SceneObjectGroup> attachments = m_presence.Attachments;
List<SceneObjectGroup> attachments = m_presence.GetAttachments();
Assert.That(attachments.Count, Is.EqualTo(1));
SceneObjectGroup attSo = attachments[0];
Assert.That(attSo.Name, Is.EqualTo(attName));
@@ -140,7 +140,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
// Check scene presence status
Assert.That(m_presence.HasAttachments(), Is.True);
List<SceneObjectGroup> attachments = m_presence.Attachments;
List<SceneObjectGroup> attachments = m_presence.GetAttachments();
Assert.That(attachments.Count, Is.EqualTo(1));
SceneObjectGroup attSo = attachments[0];
Assert.That(attSo.Name, Is.EqualTo(attName));
@@ -174,7 +174,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
// Check scene presence status
Assert.That(m_presence.HasAttachments(), Is.False);
List<SceneObjectGroup> attachments = m_presence.Attachments;
List<SceneObjectGroup> attachments = m_presence.GetAttachments();
Assert.That(attachments.Count, Is.EqualTo(0));
// Check appearance status
@@ -208,7 +208,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
// Check status on scene presence
Assert.That(m_presence.HasAttachments(), Is.False);
List<SceneObjectGroup> attachments = m_presence.Attachments;
List<SceneObjectGroup> attachments = m_presence.GetAttachments();
Assert.That(attachments.Count, Is.EqualTo(0));
// Check item status
@@ -237,7 +237,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
ScenePresence presence = SceneHelpers.AddScenePresence(scene, acd);
Assert.That(presence.HasAttachments(), Is.True);
List<SceneObjectGroup> attachments = presence.Attachments;
List<SceneObjectGroup> attachments = presence.GetAttachments();
Assert.That(attachments.Count, Is.EqualTo(1));
SceneObjectGroup attSo = attachments[0];