From 32444d98cb13423fdf8c874e4fbb7ea17670d7c5 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 31 Aug 2011 16:29:51 +0100 Subject: 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. --- .../Avatar/Attachments/AttachmentsModule.cs | 19 +++++++------------ .../Attachments/Tests/AttachmentsModuleTests.cs | 10 +++++----- 2 files changed, 12 insertions(+), 17 deletions(-) (limited to 'OpenSim/Region/CoreModules/Avatar') diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index f4bc495..9e5ce8f 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -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 attachments = new List(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 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); diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs index b0146a1..363e258 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs @@ -106,7 +106,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests // Check status on scene presence Assert.That(m_presence.HasAttachments(), Is.True); - List attachments = m_presence.Attachments; + List 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 attachments = m_presence.Attachments; + List 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 attachments = m_presence.Attachments; + List 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 attachments = m_presence.Attachments; + List 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 attachments = presence.Attachments; + List attachments = presence.GetAttachments(); Assert.That(attachments.Count, Is.EqualTo(1)); SceneObjectGroup attSo = attachments[0]; -- cgit v1.1