lock AvatarAppearance.m_attachments when we use it

This is partly to address http://opensimulator.org/mantis/view.php?id=5644, though something more thorough is needed.
remove-scene-viewer
Justin Clark-Casey (justincc) 2011-09-12 21:05:26 +01:00
parent 44a491f36b
commit dab6387bba
1 changed files with 58 additions and 33 deletions

View File

@ -391,10 +391,14 @@ namespace OpenSim.Framework
public List<AvatarAttachment> GetAttachments()
{
List<AvatarAttachment> alist = new List<AvatarAttachment>();
foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
lock (m_attachments)
{
foreach (AvatarAttachment attach in kvp.Value)
alist.Add(new AvatarAttachment(attach));
foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
{
foreach (AvatarAttachment attach in kvp.Value)
alist.Add(new AvatarAttachment(attach));
}
}
return alist;
@ -406,10 +410,13 @@ namespace OpenSim.Framework
// "[AVATAR APPEARNCE]: Appending itemID={0}, assetID={1} at {2}",
// attach.ItemID, attach.AssetID, attach.AttachPoint);
if (!m_attachments.ContainsKey(attach.AttachPoint))
m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
lock (m_attachments)
{
if (!m_attachments.ContainsKey(attach.AttachPoint))
m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
m_attachments[attach.AttachPoint].Add(attach);
m_attachments[attach.AttachPoint].Add(attach);
}
}
internal void ReplaceAttachment(AvatarAttachment attach)
@ -418,8 +425,11 @@ namespace OpenSim.Framework
// "[AVATAR APPEARANCE]: Replacing itemID={0}, assetID={1} at {2}",
// attach.ItemID, attach.AssetID, attach.AttachPoint);
m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
m_attachments[attach.AttachPoint].Add(attach);
lock (m_attachments)
{
m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
m_attachments[attach.AttachPoint].Add(attach);
}
}
/// <summary>
@ -448,10 +458,13 @@ namespace OpenSim.Framework
if (item == UUID.Zero)
{
if (m_attachments.ContainsKey(attachpoint))
lock (m_attachments)
{
m_attachments.Remove(attachpoint);
return true;
if (m_attachments.ContainsKey(attachpoint))
{
m_attachments.Remove(attachpoint);
return true;
}
}
return false;
@ -494,11 +507,14 @@ namespace OpenSim.Framework
/// <returns>Returns null if this item is not attached.</returns>
public AvatarAttachment GetAttachmentForItem(UUID itemID)
{
foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
lock (m_attachments)
{
int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; });
if (index >= 0)
return kvp.Value[index];
foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
{
int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; });
if (index >= 0)
return kvp.Value[index];
}
}
return null;
@ -506,11 +522,14 @@ namespace OpenSim.Framework
public int GetAttachpoint(UUID itemID)
{
foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
lock (m_attachments)
{
int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; });
if (index >= 0)
return kvp.Key;
foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
{
int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; });
if (index >= 0)
return kvp.Key;
}
}
return 0;
@ -518,27 +537,32 @@ namespace OpenSim.Framework
public bool DetachAttachment(UUID itemID)
{
foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
lock (m_attachments)
{
int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; });
if (index >= 0)
foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
{
// Remove it from the list of attachments at that attach point
m_attachments[kvp.Key].RemoveAt(index);
int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; });
if (index >= 0)
{
// Remove it from the list of attachments at that attach point
m_attachments[kvp.Key].RemoveAt(index);
// And remove the list if there are no more attachments here
if (m_attachments[kvp.Key].Count == 0)
m_attachments.Remove(kvp.Key);
// And remove the list if there are no more attachments here
if (m_attachments[kvp.Key].Count == 0)
m_attachments.Remove(kvp.Key);
return true;
return true;
}
}
}
return false;
}
public void ClearAttachments()
{
m_attachments.Clear();
lock (m_attachments)
m_attachments.Clear();
}
#region Packing Functions
@ -576,7 +600,8 @@ namespace OpenSim.Framework
data["visualparams"] = visualparams;
// Attachments
OSDArray attachs = new OSDArray(m_attachments.Count);
List<AvatarAttachment> attachments = GetAttachments();
OSDArray attachs = new OSDArray(attachments.Count);
foreach (AvatarAttachment attach in GetAttachments())
attachs.Add(attach.Pack());
data["attachments"] = attachs;