From 2864c45678a6e2557b6e2fda294d06cc8bfcec10 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sun, 12 Apr 2009 12:03:07 +0000 Subject: [PATCH] Actually remove the script if it tries to remove itself. Fixes Mantis #2929 --- .../DotNetEngine/EventQueueThreadClass.cs | 10 ++++++++++ .../Shared/Api/Implementation/LSL_Api.cs | 5 ++++- OpenSim/Region/ScriptEngine/Shared/Helpers.cs | 14 ++++++++++++++ .../ScriptEngine/Shared/Instance/ScriptInstance.cs | 14 ++++++++++---- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueThreadClass.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueThreadClass.cs index 5451df237e..425d349846 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueThreadClass.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueThreadClass.cs @@ -168,6 +168,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine private ScriptEngine lastScriptEngine; private uint lastLocalID; + private UUID lastItemID; // Queue processing thread loop private void EventQueueThreadLoop() @@ -201,6 +202,14 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine lastScriptEngine.World.DeleteSceneObject( part.ParentGroup, false); } + catch (ScriptDeleteException) // Must delete item + { + SceneObjectPart part = + lastScriptEngine.World.GetSceneObjectPart( + lastLocalID); + if (part != null && part.ParentGroup != null) + part.Inventory.RemoveInventoryItem(lastItemID); + } catch (Exception e) { m_log.ErrorFormat("[{0}]: Exception {1} thrown", ScriptEngineName, e.GetType().ToString()); @@ -284,6 +293,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine QIS.localID)) { lastLocalID = QIS.localID; + lastItemID = QIS.itemID; LastExecutionStarted = DateTime.Now.Ticks; KillCurrentScript = false; InExecution = true; diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index f4e7990ef2..0964821a66 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -3577,7 +3577,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { if (item.Name == name) { - m_host.Inventory.RemoveInventoryItem(item.ItemID); + if (item.ItemID == m_itemID) + throw new ScriptDeleteException(); + else + m_host.Inventory.RemoveInventoryItem(item.ItemID); return; } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs index 4236c2b7b1..df9c13aa21 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs @@ -66,6 +66,20 @@ namespace OpenSim.Region.ScriptEngine.Shared } } + [Serializable] + public class ScriptDeleteException : Exception + { + public ScriptDeleteException() + { + } + + protected ScriptDeleteException( + SerializationInfo info, + StreamingContext context) + { + } + } + public class DetectParams { public DetectParams() diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 66691b7393..1c865e8ccd 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs @@ -707,11 +707,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance } catch (Exception e) { - m_log.DebugFormat("[Script] Exception: {0}", e.Message); + // m_log.DebugFormat("[SCRIPT] Exception: {0}", e.Message); m_InEvent = false; m_CurrentEvent = String.Empty; - if ((!(e is TargetInvocationException) || !(e.InnerException is SelfDeleteException)) && (!(e is ThreadAbortException))) + if ((!(e is TargetInvocationException) || (!(e.InnerException is SelfDeleteException) && !(e.InnerException is ScriptDeleteException))) && !(e is ThreadAbortException)) { try { @@ -727,10 +727,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance } catch (Exception e2) // LEGIT: User Scripting { - m_log.Error("[Script]: "+ + m_log.Error("[SCRIPT]: "+ "Error displaying error in-world: " + e2.ToString()); - m_log.Error("[Script]: " + + m_log.Error("[SCRIPT]: " + "Errormessage: Error compiling script:\r\n" + e.ToString()); } @@ -741,6 +741,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance if (part != null && part.ParentGroup != null) m_Engine.World.DeleteSceneObject(part.ParentGroup, false); } + else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) + { + m_InSelfDelete = true; + if (part != null && part.ParentGroup != null) + part.Inventory.RemoveInventoryItem(m_ItemID); + } } } }