Start locking entire add/remove operations on an IScenePresence.AttachmentsSyncLock object
Attach and detach packets are processed asynchronously when received from a viewer. Bugs like http://opensimulator.org/mantis/view.php?id=5644 indicate that in some situations (such as attaching/detaching entire folders of objects at once), there are race conditions between these threads. Since multiple data structures need to be updated on attach/detach, it's not enough to lock the individual collections. Therefore, this commit introduces a new IScenePresence.AttachmentsSyncLock which add/remove operations lock on.remove-scene-viewer
parent
dab6387bba
commit
ea0f78c971
|
@ -240,15 +240,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
|
||||||
|
|
||||||
private bool AttachObject(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent)
|
private bool AttachObject(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent)
|
||||||
{
|
{
|
||||||
// m_log.DebugFormat(
|
lock (sp.AttachmentsSyncLock)
|
||||||
// "[ATTACHMENTS MODULE]: Attaching object {0} {1} to {2} point {3} from ground (silent = {4})",
|
{
|
||||||
// group.Name, group.LocalId, sp.Name, attachmentPt, silent);
|
// m_log.DebugFormat(
|
||||||
|
// "[ATTACHMENTS MODULE]: Attaching object {0} {1} to {2} point {3} from ground (silent = {4})",
|
||||||
|
// group.Name, group.LocalId, sp.Name, attachmentPt, silent);
|
||||||
|
|
||||||
if (sp.GetAttachments(attachmentPt).Contains(group))
|
if (sp.GetAttachments(attachmentPt).Contains(group))
|
||||||
{
|
{
|
||||||
// m_log.WarnFormat(
|
// m_log.WarnFormat(
|
||||||
// "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached",
|
// "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached",
|
||||||
// group.Name, group.LocalId, sp.Name, AttachmentPt);
|
// group.Name, group.LocalId, sp.Name, AttachmentPt);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -313,6 +315,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
|
||||||
}
|
}
|
||||||
|
|
||||||
AttachToAgent(sp, group, attachmentPt, attachPos, silent);
|
AttachToAgent(sp, group, attachmentPt, attachPos, silent);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -321,15 +324,27 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
|
||||||
IClientAPI remoteClient,
|
IClientAPI remoteClient,
|
||||||
RezMultipleAttachmentsFromInvPacket.HeaderDataBlock header,
|
RezMultipleAttachmentsFromInvPacket.HeaderDataBlock header,
|
||||||
RezMultipleAttachmentsFromInvPacket.ObjectDataBlock[] objects)
|
RezMultipleAttachmentsFromInvPacket.ObjectDataBlock[] objects)
|
||||||
|
{
|
||||||
|
ScenePresence sp = m_scene.GetScenePresence(remoteClient.AgentId);
|
||||||
|
|
||||||
|
if (sp == null)
|
||||||
|
{
|
||||||
|
m_log.ErrorFormat(
|
||||||
|
"[ATTACHMENTS MODULE]: Could not find presence for client {0} {1} in RezMultipleAttachmentsFromInventory()",
|
||||||
|
remoteClient.Name, remoteClient.AgentId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lock (sp.AttachmentsSyncLock)
|
||||||
{
|
{
|
||||||
foreach (RezMultipleAttachmentsFromInvPacket.ObjectDataBlock obj in objects)
|
foreach (RezMultipleAttachmentsFromInvPacket.ObjectDataBlock obj in objects)
|
||||||
{
|
{
|
||||||
RezSingleAttachmentFromInventory(remoteClient, obj.ItemID, obj.AttachmentPt);
|
RezSingleAttachmentFromInventory(sp, obj.ItemID, obj.AttachmentPt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISceneEntity RezSingleAttachmentFromInventory(
|
public ISceneEntity RezSingleAttachmentFromInventory(IClientAPI remoteClient, UUID itemID, uint AttachmentPt)
|
||||||
IClientAPI remoteClient, UUID itemID, uint AttachmentPt)
|
|
||||||
{
|
{
|
||||||
// m_log.DebugFormat(
|
// m_log.DebugFormat(
|
||||||
// "[ATTACHMENTS MODULE]: Rezzing attachment to point {0} from item {1} for {2}",
|
// "[ATTACHMENTS MODULE]: Rezzing attachment to point {0} from item {1} for {2}",
|
||||||
|
@ -345,6 +360,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return RezSingleAttachmentFromInventory(sp, itemID, AttachmentPt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ISceneEntity RezSingleAttachmentFromInventory(ScenePresence sp, UUID itemID, uint AttachmentPt)
|
||||||
|
{
|
||||||
// TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should
|
// TODO: this short circuits multiple attachments functionality in LL viewer 2.1+ and should
|
||||||
// be removed when that functionality is implemented in opensim
|
// be removed when that functionality is implemented in opensim
|
||||||
AttachmentPt &= 0x7f;
|
AttachmentPt &= 0x7f;
|
||||||
|
@ -362,6 +382,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
|
||||||
{
|
{
|
||||||
IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>();
|
IInventoryAccessModule invAccess = m_scene.RequestModuleInterface<IInventoryAccessModule>();
|
||||||
if (invAccess != null)
|
if (invAccess != null)
|
||||||
|
{
|
||||||
|
lock (sp.AttachmentsSyncLock)
|
||||||
{
|
{
|
||||||
SceneObjectGroup objatt;
|
SceneObjectGroup objatt;
|
||||||
|
|
||||||
|
@ -374,9 +396,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
|
||||||
null, assetID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
|
null, assetID, Vector3.Zero, Vector3.Zero, UUID.Zero, (byte)1, true,
|
||||||
false, false, sp.UUID, true);
|
false, false, sp.UUID, true);
|
||||||
|
|
||||||
// m_log.DebugFormat(
|
// m_log.DebugFormat(
|
||||||
// "[ATTACHMENTS MODULE]: Retrieved single object {0} for attachment to {1} on point {2}",
|
// "[ATTACHMENTS MODULE]: Retrieved single object {0} for attachment to {1} on point {2}",
|
||||||
// objatt.Name, remoteClient.Name, AttachmentPt);
|
// objatt.Name, remoteClient.Name, AttachmentPt);
|
||||||
|
|
||||||
if (objatt != null)
|
if (objatt != null)
|
||||||
{
|
{
|
||||||
|
@ -413,6 +435,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
|
||||||
|
|
||||||
// Do this last so that event listeners have access to all the effects of the attachment
|
// Do this last so that event listeners have access to all the effects of the attachment
|
||||||
m_scene.EventManager.TriggerOnAttach(objatt.LocalId, itemID, sp.UUID);
|
m_scene.EventManager.TriggerOnAttach(objatt.LocalId, itemID, sp.UUID);
|
||||||
|
|
||||||
|
return objatt;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -420,8 +444,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
|
||||||
"[ATTACHMENTS MODULE]: Could not retrieve item {0} for attaching to avatar {1} at point {2}",
|
"[ATTACHMENTS MODULE]: Could not retrieve item {0} for attaching to avatar {1} at point {2}",
|
||||||
itemID, sp.Name, attachmentPt);
|
itemID, sp.Name, attachmentPt);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return objatt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -473,6 +496,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
|
||||||
{
|
{
|
||||||
ScenePresence presence;
|
ScenePresence presence;
|
||||||
if (m_scene.TryGetScenePresence(remoteClient.AgentId, out presence))
|
if (m_scene.TryGetScenePresence(remoteClient.AgentId, out presence))
|
||||||
|
{
|
||||||
|
lock (presence.AttachmentsSyncLock)
|
||||||
{
|
{
|
||||||
// Save avatar attachment information
|
// Save avatar attachment information
|
||||||
m_log.Debug("[ATTACHMENTS MODULE]: Detaching from UserID: " + remoteClient.AgentId + ", ItemID: " + itemID);
|
m_log.Debug("[ATTACHMENTS MODULE]: Detaching from UserID: " + remoteClient.AgentId + ", ItemID: " + itemID);
|
||||||
|
@ -484,6 +509,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
|
||||||
DetachSingleAttachmentToInv(itemID, presence);
|
DetachSingleAttachmentToInv(itemID, presence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void DetachSingleAttachmentToGround(uint soLocalId, IClientAPI remoteClient)
|
public void DetachSingleAttachmentToGround(uint soLocalId, IClientAPI remoteClient)
|
||||||
{
|
{
|
||||||
|
@ -507,6 +533,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
|
||||||
|
|
||||||
ScenePresence presence;
|
ScenePresence presence;
|
||||||
if (m_scene.TryGetScenePresence(remoteClient.AgentId, out presence))
|
if (m_scene.TryGetScenePresence(remoteClient.AgentId, out presence))
|
||||||
|
{
|
||||||
|
lock (presence.AttachmentsSyncLock)
|
||||||
{
|
{
|
||||||
if (!m_scene.Permissions.CanRezObject(
|
if (!m_scene.Permissions.CanRezObject(
|
||||||
so.PrimCount, remoteClient.AgentId, presence.AbsolutePosition))
|
so.PrimCount, remoteClient.AgentId, presence.AbsolutePosition))
|
||||||
|
@ -527,6 +555,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
|
||||||
|
|
||||||
m_scene.EventManager.TriggerOnAttach(so.LocalId, so.UUID, UUID.Zero);
|
m_scene.EventManager.TriggerOnAttach(so.LocalId, so.UUID, UUID.Zero);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Detach the given scene object to the ground.
|
/// Detach the given scene object to the ground.
|
||||||
|
@ -567,6 +596,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
|
||||||
EntityBase[] detachEntities = m_scene.GetEntities();
|
EntityBase[] detachEntities = m_scene.GetEntities();
|
||||||
SceneObjectGroup group;
|
SceneObjectGroup group;
|
||||||
|
|
||||||
|
lock (sp.AttachmentsSyncLock)
|
||||||
|
{
|
||||||
foreach (EntityBase entity in detachEntities)
|
foreach (EntityBase entity in detachEntities)
|
||||||
{
|
{
|
||||||
if (entity is SceneObjectGroup)
|
if (entity is SceneObjectGroup)
|
||||||
|
@ -602,6 +633,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void UpdateAttachmentPosition(SceneObjectGroup sog, Vector3 pos)
|
public void UpdateAttachmentPosition(SceneObjectGroup sog, Vector3 pos)
|
||||||
{
|
{
|
||||||
|
|
|
@ -87,6 +87,15 @@ namespace OpenSim.Region.Framework.Interfaces
|
||||||
/// <returns>The scene object that was attached. Null if the scene object could not be found</returns>
|
/// <returns>The scene object that was attached. Null if the scene object could not be found</returns>
|
||||||
ISceneEntity RezSingleAttachmentFromInventory(IClientAPI remoteClient, UUID itemID, uint AttachmentPt);
|
ISceneEntity RezSingleAttachmentFromInventory(IClientAPI remoteClient, UUID itemID, uint AttachmentPt);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rez an attachment from user inventory and change inventory status to match.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sp"></param>
|
||||||
|
/// <param name="itemID"></param>
|
||||||
|
/// <param name="AttachmentPt"></param>
|
||||||
|
/// <returns>The scene object that was attached. Null if the scene object could not be found</returns>
|
||||||
|
ISceneEntity RezSingleAttachmentFromInventory(ScenePresence sp, UUID itemID, uint AttachmentPt);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Rez multiple attachments from a user's inventory
|
/// Rez multiple attachments from a user's inventory
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -60,6 +60,14 @@ namespace OpenSim.Region.Framework.Interfaces
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
AvatarAppearance Appearance { get; set; }
|
AvatarAppearance Appearance { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The AttachmentsModule synchronizes on this to avoid race conditions between commands to add and remove attachments.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// All add and remove attachment operations must synchronize on this for the lifetime of their operations.
|
||||||
|
/// </remarks>
|
||||||
|
Object AttachmentsSyncLock { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The scene objects attached to this avatar.
|
/// The scene objects attached to this avatar.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -120,6 +120,8 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>();
|
protected List<SceneObjectGroup> m_attachments = new List<SceneObjectGroup>();
|
||||||
|
|
||||||
|
public Object AttachmentsSyncLock { get; private set; }
|
||||||
|
|
||||||
private Dictionary<UUID, ScriptControllers> scriptedcontrols = new Dictionary<UUID, ScriptControllers>();
|
private Dictionary<UUID, ScriptControllers> scriptedcontrols = new Dictionary<UUID, ScriptControllers>();
|
||||||
private ScriptControlled IgnoredControls = ScriptControlled.CONTROL_ZERO;
|
private ScriptControlled IgnoredControls = ScriptControlled.CONTROL_ZERO;
|
||||||
private ScriptControlled LastCommands = ScriptControlled.CONTROL_ZERO;
|
private ScriptControlled LastCommands = ScriptControlled.CONTROL_ZERO;
|
||||||
|
@ -709,6 +711,8 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
public ScenePresence(
|
public ScenePresence(
|
||||||
IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance, PresenceType type)
|
IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance, PresenceType type)
|
||||||
{
|
{
|
||||||
|
AttachmentsSyncLock = new Object();
|
||||||
|
|
||||||
m_sendCourseLocationsMethod = SendCoarseLocationsDefault;
|
m_sendCourseLocationsMethod = SendCoarseLocationsDefault;
|
||||||
m_sceneViewer = new SceneViewer(this);
|
m_sceneViewer = new SceneViewer(this);
|
||||||
m_animator = new ScenePresenceAnimator(this);
|
m_animator = new ScenePresenceAnimator(this);
|
||||||
|
|
Loading…
Reference in New Issue