diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index 9e5ce8ff17..587f35edb3 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -147,6 +147,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments } } } + + public void DeleteAttachmentsFromScene(IScenePresence sp, bool silent) + { + foreach (SceneObjectGroup sop in sp.GetAttachments()) + { + sop.Scene.DeleteSceneObject(sop, silent); + } + + sp.ClearAttachments(); + } /// /// Called by client diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index c24cc17ecf..82bdf2052b 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -559,11 +559,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer protected virtual void AgentHasMovedAway(ScenePresence sp, bool logout) { - foreach (SceneObjectGroup sop in sp.GetAttachments()) - { - sop.Scene.DeleteSceneObject(sop, true); - } - sp.ClearAttachments(); + sp.Scene.AttachmentsModule.DeleteAttachmentsFromScene(sp, true); } protected void KillEntity(Scene scene, uint localID) diff --git a/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs index ce795f1e66..dd11ded8a6 100644 --- a/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs @@ -47,6 +47,15 @@ namespace OpenSim.Region.Framework.Interfaces /// void SaveChangedAttachments(IScenePresence sp); + /// + /// Delete all the presence's attachments from the scene + /// + /// + /// This is done when a root agent leaves/is demoted to child (for instance, on logout, teleport or region cross). + /// + /// + void DeleteAttachmentsFromScene(IScenePresence sp, bool silent); + /// /// Attach an object to an avatar from the world. /// diff --git a/OpenSim/Region/Framework/Interfaces/IScenePresence.cs b/OpenSim/Region/Framework/Interfaces/IScenePresence.cs index 788b36ffc7..91e4bf2c15 100644 --- a/OpenSim/Region/Framework/Interfaces/IScenePresence.cs +++ b/OpenSim/Region/Framework/Interfaces/IScenePresence.cs @@ -62,9 +62,22 @@ namespace OpenSim.Region.Framework.Interfaces /// A copy of the list. /// /// - /// Do not change this list directly - use methods such as - /// AddAttachment() and RemoveAttachment(). + /// Do not change this list directly - use the attachments module. /// List GetAttachments(); + + /// + /// The scene objects attached to this avatar at a specific attachment point. + /// + /// + /// + List GetAttachments(uint attachmentPoint); + + bool HasAttachments(); + + // Don't use these methods directly. Instead, use the AttachmentsModule + void AddAttachment(SceneObjectGroup gobj); + void RemoveAttachment(SceneObjectGroup gobj); + void ClearAttachments(); } } \ No newline at end of file diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 5e96b0aa90..0d284a533e 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -3401,19 +3401,7 @@ namespace OpenSim.Region.Framework.Scenes public void Close() { - lock (m_attachments) - { - // Delete attachments from scene - // Don't try to save, as this thread won't live long - // enough to complete the save. This would cause no copy - // attachments to poof! - // - foreach (SceneObjectGroup grp in m_attachments) - { - m_scene.DeleteSceneObject(grp, false); - } - m_attachments.Clear(); - } + m_scene.AttachmentsModule.DeleteAttachmentsFromScene(this, false); lock (m_knownChildRegions) { diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index e58dca2d9c..2fdeeabe69 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -143,11 +143,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC if (!m_avatars.ContainsKey(agentId)) return false; - // FIXME: An extremely bad bit of code that reaches directly into the attachments list and manipulates it - foreach (SceneObjectGroup att in sp.GetAttachments()) - scene.DeleteSceneObject(att, false); - - sp.ClearAttachments(); + scene.AttachmentsModule.DeleteAttachmentsFromScene(sp, false); AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); sp.Appearance = npcAppearance;