When an attachment is detached to inv or derezzed, stop the scripts, update the known item with script state still in the script engine and then remove the scripts.

This is to fix a regression starting from 5301648 where attachments had to start being deleted before persistence in order to avoid race conditions with hud update threads.
0.7.3-extended
Justin Clark-Casey (justincc) 2012-07-10 22:41:11 +01:00
parent 35457448ca
commit e21dd88ed5
5 changed files with 110 additions and 13 deletions

View File

@ -211,16 +211,20 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
lock (sp.AttachmentsSyncLock)
{
foreach (SceneObjectGroup grp in sp.GetAttachments())
foreach (SceneObjectGroup so in sp.GetAttachments())
{
grp.Scene.DeleteSceneObject(grp, false);
// We can only remove the script instances from the script engine after we've retrieved their xml state
// when we update the attachment item.
m_scene.DeleteSceneObject(so, false, false);
if (saveChanged || saveAllScripted)
{
grp.IsAttachment = false;
grp.AbsolutePosition = grp.RootPart.AttachedPos;
UpdateKnownItem(sp, grp, saveAllScripted);
so.IsAttachment = false;
so.AbsolutePosition = so.RootPart.AttachedPos;
UpdateKnownItem(sp, so, saveAllScripted);
}
so.RemoveScriptInstances(true);
}
sp.ClearAttachments();
@ -682,7 +686,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
m_scene.EventManager.TriggerOnAttach(so.LocalId, so.FromItemID, UUID.Zero);
sp.RemoveAttachment(so);
m_scene.DeleteSceneObject(so, false);
// We can only remove the script instances from the script engine after we've retrieved their xml state
// when we update the attachment item.
m_scene.DeleteSceneObject(so, false, false);
// Prepare sog for storage
so.AttachedAvatar = UUID.Zero;
@ -691,6 +698,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
so.AbsolutePosition = so.RootPart.AttachedPos;
UpdateKnownItem(sp, so, true);
so.RemoveScriptInstances(true);
}
private SceneObjectGroup RezSingleAttachmentFromInventoryInternal(

View File

@ -92,7 +92,7 @@ namespace OpenSim.Region.Framework.Interfaces
void ResumeScripts();
/// <summary>
/// Stop all the scripts in this entity.
/// Stop and remove all the scripts in this entity from the scene.
/// </summary>
/// <param name="sceneObjectBeingDeleted">
/// Should be true if these scripts are being removed because the scene
@ -100,6 +100,11 @@ namespace OpenSim.Region.Framework.Interfaces
/// </param>
void RemoveScriptInstances(bool sceneObjectBeingDeleted);
/// <summary>
/// Stop all the scripts in this entity.
/// </summary>
void StopScriptInstances();
/// <summary>
/// Start a script which is in this entity's inventory.
/// </summary>
@ -129,7 +134,7 @@ namespace OpenSim.Region.Framework.Interfaces
bool CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource);
/// <summary>
/// Stop a script which is in this prim's inventory.
/// Stop and remove a script which is in this prim's inventory from the scene.
/// </summary>
/// <param name="itemId"></param>
/// <param name="sceneObjectBeingDeleted">
@ -138,6 +143,12 @@ namespace OpenSim.Region.Framework.Interfaces
/// </param>
void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted);
/// <summary>
/// Stop a script which is in this prim's inventory.
/// </summary>
/// <param name="itemId"></param>
void StopScriptInstance(UUID itemId);
/// <summary>
/// Add an item to this entity's inventory. If an item with the same name already exists, then an alternative
/// name is chosen.

View File

@ -2135,13 +2135,30 @@ namespace OpenSim.Region.Framework.Scenes
/// <summary>
/// Synchronously delete the given object from the scene.
/// </summary>
/// <remarks>
/// Scripts are also removed.
/// </remarks>
/// <param name="group">Object Id</param>
/// <param name="silent">Suppress broadcasting changes to other clients.</param>
public void DeleteSceneObject(SceneObjectGroup group, bool silent)
{
DeleteSceneObject(group, silent, true);
}
/// <summary>
/// Synchronously delete the given object from the scene.
/// </summary>
/// <param name="group">Object Id</param>
/// <param name="silent">Suppress broadcasting changes to other clients.</param>
/// <param name="removeScripts">If true, then scripts are removed. If false, then they are only stopped.</para>
public void DeleteSceneObject(SceneObjectGroup group, bool silent, bool removeScripts)
{
// m_log.DebugFormat("[SCENE]: Deleting scene object {0} {1}", group.Name, group.UUID);
group.RemoveScriptInstances(true);
if (removeScripts)
group.RemoveScriptInstances(true);
else
group.StopScriptInstances();
SceneObjectPart[] partList = group.Parts;

View File

@ -79,7 +79,7 @@ namespace OpenSim.Region.Framework.Scenes
}
/// <summary>
/// Stop the scripts contained in all the prims in this group
/// Stop and remove the scripts contained in all the prims in this group
/// </summary>
/// <param name="sceneObjectBeingDeleted">
/// Should be true if these scripts are being removed because the scene
@ -92,6 +92,14 @@ namespace OpenSim.Region.Framework.Scenes
parts[i].Inventory.RemoveScriptInstances(sceneObjectBeingDeleted);
}
/// <summary>
/// Stop the scripts contained in all the prims in this group
/// </summary>
public void StopScriptInstances()
{
Array.ForEach<SceneObjectPart>(m_parts.GetArray(), p => p.Inventory.StopScriptInstances());
}
/// <summary>
/// Add an inventory item from a user's inventory to a prim in this scene object.
/// </summary>

View File

@ -250,7 +250,7 @@ namespace OpenSim.Region.Framework.Scenes
}
/// <summary>
/// Stop all the scripts in this prim.
/// Stop and remove all the scripts in this prim.
/// </summary>
/// <param name="sceneObjectBeingDeleted">
/// Should be true if these scripts are being removed because the scene
@ -263,6 +263,14 @@ namespace OpenSim.Region.Framework.Scenes
RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted);
}
/// <summary>
/// Stop all the scripts in this prim.
/// </summary>
public void StopScriptInstances()
{
GetInventoryItems(InventoryType.LSL).ForEach(i => StopScriptInstance(i));
}
/// <summary>
/// Start a script which is in this prim's inventory.
/// </summary>
@ -410,7 +418,7 @@ namespace OpenSim.Region.Framework.Scenes
}
/// <summary>
/// Stop a script which is in this prim's inventory.
/// Stop and remove a script which is in this prim's inventory.
/// </summary>
/// <param name="itemId"></param>
/// <param name="sceneObjectBeingDeleted">
@ -437,7 +445,7 @@ namespace OpenSim.Region.Framework.Scenes
}
else
{
m_log.ErrorFormat(
m_log.WarnFormat(
"[PRIM INVENTORY]: " +
"Couldn't stop script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}",
itemId, m_part.Name, m_part.UUID,
@ -445,6 +453,51 @@ namespace OpenSim.Region.Framework.Scenes
}
}
/// <summary>
/// Stop a script which is in this prim's inventory.
/// </summary>
/// <param name="itemId"></param>
/// <param name="sceneObjectBeingDeleted">
/// Should be true if this script is being removed because the scene
/// object is being deleted. This will prevent spurious updates to the client.
/// </param>
public void StopScriptInstance(UUID itemId)
{
TaskInventoryItem scriptItem;
lock (m_items)
m_items.TryGetValue(itemId, out scriptItem);
if (scriptItem != null)
{
StopScriptInstance(scriptItem);
}
else
{
m_log.WarnFormat(
"[PRIM INVENTORY]: " +
"Couldn't stop script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}",
itemId, m_part.Name, m_part.UUID,
m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
}
}
/// <summary>
/// Stop a script which is in this prim's inventory.
/// </summary>
/// <param name="itemId"></param>
/// <param name="sceneObjectBeingDeleted">
/// Should be true if this script is being removed because the scene
/// object is being deleted. This will prevent spurious updates to the client.
/// </param>
public void StopScriptInstance(TaskInventoryItem item)
{
m_part.ParentGroup.Scene.EventManager.TriggerStopScript(m_part.LocalId, item.ItemID);
// At the moment, even stopped scripts are counted as active, which is probably wrong.
// m_part.ParentGroup.AddActiveScriptCount(-1);
}
/// <summary>
/// Check if the inventory holds an item with a given name.
/// </summary>