Perform SceneGraph.DuplicateObject() under existing m_updateLock already used for link and delinking, in order to avoid race conditions.

DuplicateObject() relies on source object having correct link numbers for the duration of the dupe.
Both link and delink can change link numbers such that they are not consistent for short periods of time.
0.7.4.1
Justin Clark-Casey (justincc) 2012-05-08 21:31:35 +01:00
parent 5d1d47e1f9
commit abbd050a13
1 changed files with 97 additions and 83 deletions

View File

@ -92,8 +92,12 @@ namespace OpenSim.Region.Framework.Scenes
protected internal Dictionary<uint, SceneObjectGroup> SceneObjectGroupsByLocalPartID = new Dictionary<uint, SceneObjectGroup>(); protected internal Dictionary<uint, SceneObjectGroup> SceneObjectGroupsByLocalPartID = new Dictionary<uint, SceneObjectGroup>();
/// <summary> /// <summary>
/// Lock to prevent object group update, linking and delinking operations from running concurrently. /// Lock to prevent object group update, linking, delinking and duplication operations from running concurrently.
/// </summary> /// </summary>
/// <remarks>
/// These operations rely on the parts composition of the object. If allowed to run concurrently then race
/// conditions can occur.
/// </remarks>
private Object m_updateLock = new Object(); private Object m_updateLock = new Object();
#endregion #endregion
@ -1844,18 +1848,31 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="AgentID"></param> /// <param name="AgentID"></param>
/// <param name="GroupID"></param> /// <param name="GroupID"></param>
/// <param name="rot"></param> /// <param name="rot"></param>
public SceneObjectGroup DuplicateObject(uint originalPrimID, Vector3 offset, uint flags, UUID AgentID, UUID GroupID, Quaternion rot) /// <returns>null if duplication fails, otherwise the duplicated object</returns>
public SceneObjectGroup DuplicateObject(
uint originalPrimID, Vector3 offset, uint flags, UUID AgentID, UUID GroupID, Quaternion rot)
{
Monitor.Enter(m_updateLock);
try
{ {
// m_log.DebugFormat( // m_log.DebugFormat(
// "[SCENE]: Duplication of object {0} at offset {1} requested by agent {2}", // "[SCENE]: Duplication of object {0} at offset {1} requested by agent {2}",
// originalPrimID, offset, AgentID); // originalPrimID, offset, AgentID);
SceneObjectGroup original = GetGroupByPrim(originalPrimID); SceneObjectGroup original = GetGroupByPrim(originalPrimID);
if (original != null) if (original == null)
{ {
if (m_parentScene.Permissions.CanDuplicateObject( m_log.WarnFormat(
"[SCENEGRAPH]: Attempt to duplicate nonexistant prim id {0} by {1}", originalPrimID, AgentID);
return null;
}
if (!m_parentScene.Permissions.CanDuplicateObject(
original.PrimCount, original.UUID, AgentID, original.AbsolutePosition)) original.PrimCount, original.UUID, AgentID, original.AbsolutePosition))
{ return null;
SceneObjectGroup copy = original.Copy(true); SceneObjectGroup copy = original.Copy(true);
copy.AbsolutePosition = copy.AbsolutePosition + offset; copy.AbsolutePosition = copy.AbsolutePosition + offset;
@ -1927,13 +1944,10 @@ namespace OpenSim.Region.Framework.Scenes
return copy; return copy;
} }
} finally
else
{ {
m_log.WarnFormat("[SCENE]: Attempted to duplicate nonexistant prim id {0}", GroupID); Monitor.Exit(m_updateLock);
} }
return null;
} }
/// <summary> /// <summary>