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.3-extended
Justin Clark-Casey (justincc) 2012-05-08 21:31:35 +01:00
parent 4eba4a37ed
commit 80030d3f15
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>();
/// <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>
/// <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();
#endregion
@ -1862,18 +1866,31 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="AgentID"></param>
/// <param name="GroupID"></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(
// "[SCENE]: Duplication of object {0} at offset {1} requested by agent {2}",
// originalPrimID, offset, AgentID);
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))
{
return null;
SceneObjectGroup copy = original.Copy(true);
copy.AbsolutePosition = copy.AbsolutePosition + offset;
@ -1945,13 +1962,10 @@ namespace OpenSim.Region.Framework.Scenes
return copy;
}
}
else
finally
{
m_log.WarnFormat("[SCENE]: Attempted to duplicate nonexistant prim id {0}", GroupID);
Monitor.Exit(m_updateLock);
}
return null;
}
/// <summary>