Lock the attachments dict so it doesn't get out of sync when iterating

avinationmerge
Melanie 2010-12-06 17:40:07 +01:00
parent 4b979362e9
commit b1a5c03985
1 changed files with 59 additions and 35 deletions

View File

@ -413,6 +413,8 @@ namespace OpenSim.Framework
/// duplicate attachpoints
/// </summary>
public List<AvatarAttachment> GetAttachments()
{
lock (m_attachments)
{
List<AvatarAttachment> alist = new List<AvatarAttachment>();
foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
@ -423,19 +425,26 @@ namespace OpenSim.Framework
return alist;
}
}
internal void AppendAttachment(AvatarAttachment attach)
{
lock (m_attachments)
{
if (!m_attachments.ContainsKey(attach.AttachPoint))
m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
m_attachments[attach.AttachPoint].Add(attach);
}
}
internal void ReplaceAttachment(AvatarAttachment attach)
{
lock (m_attachments)
{
m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
m_attachments[attach.AttachPoint].Add(attach);
}
}
/// <summary>
/// Add an attachment, if the attachpoint has the
@ -449,11 +458,14 @@ namespace OpenSim.Framework
return;
if (item == UUID.Zero)
{
lock (m_attachments)
{
if (m_attachments.ContainsKey(attachpoint))
m_attachments.Remove(attachpoint);
return;
}
}
// check if this is an append or a replace, 0x80 marks it as an append
if ((attachpoint & 0x80) > 0)
@ -469,6 +481,8 @@ namespace OpenSim.Framework
}
public int GetAttachpoint(UUID itemID)
{
lock (m_attachments)
{
foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
{
@ -479,8 +493,11 @@ namespace OpenSim.Framework
return 0;
}
}
public void DetachAttachment(UUID itemID)
{
lock (m_attachments)
{
foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
{
@ -497,11 +514,15 @@ namespace OpenSim.Framework
}
}
}
}
public void ClearAttachments()
{
lock (m_attachments)
{
m_attachments.Clear();
}
}
#region Packing Functions
@ -537,11 +558,14 @@ namespace OpenSim.Framework
OSDBinary visualparams = new OSDBinary(m_visualparams);
data["visualparams"] = visualparams;
lock (m_attachments)
{
// Attachments
OSDArray attachs = new OSDArray(m_attachments.Count);
foreach (AvatarAttachment attach in GetAttachments())
attachs.Add(attach.Pack());
data["attachments"] = attachs;
}
return data;
}