From dcf41cb68370dc1e1b03fd78edf75b175b17f6ea Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Thu, 1 Nov 2007 19:27:03 +0000 Subject: [PATCH] ScriptServer fixes: Added more debug logging, mutex lock (to be extra-super-sure) on script load/unload, removed experimental Grid-scriptengine from compile because of dynamic module loader, and added random string to script filename to bypass module loader file lock. Please delete your copy of bin/ScriptEngine/OpenSim.Grid.ScriptEngine.DotNetEngine.dll. --- .../Region/ScriptEngine/Common/Executor.cs | 7 + .../DotNetEngine/Compiler/LSL/Compiler.cs | 3 +- .../Compiler/LSL/LSL2CSConverter.cs | 4 + .../DotNetEngine/EventQueueManager.cs | 23 ++-- .../DotNetEngine/ScriptManager.cs | 124 ++++++++++-------- prebuild.xml | 55 -------- 6 files changed, 98 insertions(+), 118 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Common/Executor.cs b/OpenSim/Region/ScriptEngine/Common/Executor.cs index c656e0114c..1805e38178 100644 --- a/OpenSim/Region/ScriptEngine/Common/Executor.cs +++ b/OpenSim/Region/ScriptEngine/Common/Executor.cs @@ -82,6 +82,10 @@ namespace OpenSim.Region.ScriptEngine.Common string EventName = m_Script.State() + "_event_" + FunctionName; +#if DEBUG + Console.WriteLine("ScriptEngine: Script event function name: " + EventName); +#endif + //type.InvokeMember(EventName, BindingFlags.InvokeMethod, null, m_Script, args); //Console.WriteLine("ScriptEngine Executor.ExecuteEvent: \"" + EventName + "\""); @@ -112,6 +116,9 @@ namespace OpenSim.Region.ScriptEngine.Common return; } +#if DEBUG + Console.WriteLine("ScriptEngine: Executing function name: " + EventName); +#endif // Found //try //{ diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs index 7f452e0bbb..c81e6bd6dc 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs @@ -39,6 +39,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL private LSL2CSConverter LSL_Converter = new LSL2CSConverter(); private CSharpCodeProvider codeProvider = new CSharpCodeProvider(); private static UInt64 scriptCompileCounter = 0; + private static int instanceID = new Random().Next(0, int.MaxValue); // Implemented due to peer preassure --- will cause garbage in ScriptEngines folder ;) //private ICodeCompiler icc = codeProvider.CreateCompiler(); public string CompileFromFile(string LSOFileName) { @@ -82,7 +83,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL { // Output assembly name scriptCompileCounter++; - string OutFile = Path.Combine("ScriptEngines", "Script_" + scriptCompileCounter + ".dll"); + string OutFile = Path.Combine("ScriptEngines", "DotNetScript_" + instanceID.ToString() + "_" + scriptCompileCounter.ToString() + ".dll"); try { File.Delete(OutFile); diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs index 0c28617dfe..bbd6839abe 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs @@ -53,6 +53,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL public string Convert(string Script) { + quotes.Clear(); string Return = ""; Script = " \r\n" + Script; @@ -310,6 +311,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL Return += Script; Return += "} }\r\n"; + + quotes.Clear(); + return Return; } } diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs index d7491d91ac..f215dd5427 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs @@ -181,6 +181,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine // Execute function try { +#if DEBUG + m_ScriptEngine.Log.Debug("ScriptEngine", "Executing event:\r\n" + + "QIS.localID: " + QIS.localID + + ", QIS.itemID: " + QIS.itemID + + ", QIS.functionName: " + QIS.functionName); +#endif m_ScriptEngine.m_ScriptManager.ExecuteEvent(QIS.localID, QIS.itemID, QIS.functionName, QIS.param); } @@ -188,16 +194,17 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine { // DISPLAY ERROR INWORLD string text = "Error executing script function \"" + QIS.functionName + "\":\r\n"; - if (e.InnerException != null) - { + //if (e.InnerException != null) + //{ // Send inner exception text += e.InnerException.Message.ToString(); - } - else - { + //} + //else + //{ + text += "\r\n"; // Send normal text += e.Message.ToString(); - } + //} try { if (text.Length > 1500) @@ -214,7 +221,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine //else //{ // T oconsole - Console.WriteLine("Unable to send text in-world:\r\n" + text); + m_ScriptEngine.Log.Error("ScriptEngine", "Unable to send text in-world:\r\n" + text); } } finally @@ -230,7 +237,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine } catch (Exception e) { - Console.WriteLine("Exception in EventQueueThreadLoop: " + e.ToString()); + m_ScriptEngine.Log.Error("ScriptEngine", "Exception in EventQueueThreadLoop: " + e.ToString()); } } // while } // try diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs index 54a5ef5d8c..a3cf9f77c1 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs @@ -225,6 +225,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine #region Start/Stop/Reset script + Object startStopLock = new Object(); + /// /// Fetches, loads and hooks up a script to an objects events /// @@ -259,76 +261,83 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine StartScript(localID, itemID, script); } + // Create a new instance of the compiler (reuse) + Compiler.LSL.Compiler LSLCompiler = new Compiler.LSL.Compiler(); private void _StartScript(uint localID, LLUUID itemID, string Script) { - //IScriptHost root = host.GetRoot(); - Console.WriteLine("ScriptManager StartScript: localID: " + localID + ", itemID: " + itemID); - - // We will initialize and start the script. - // It will be up to the script itself to hook up the correct events. - string ScriptSource = ""; - - SceneObjectPart m_host = World.GetSceneObjectPart(localID); - - try + lock (startStopLock) { - // Create a new instance of the compiler (currently we don't want reuse) - Compiler.LSL.Compiler LSLCompiler = new Compiler.LSL.Compiler(); - // Compile (We assume LSL) - ScriptSource = LSLCompiler.CompileFromLSLText(Script); - //Console.WriteLine("Compilation of " + FileName + " done"); - // * Insert yield into code - ScriptSource = ProcessYield(ScriptSource); + //IScriptHost root = host.GetRoot(); + Console.WriteLine("ScriptManager StartScript: localID: " + localID + ", itemID: " + itemID); + // We will initialize and start the script. + // It will be up to the script itself to hook up the correct events. + string ScriptSource = ""; -#if DEBUG - long before; - before = GC.GetTotalMemory(true); -#endif + SceneObjectPart m_host = World.GetSceneObjectPart(localID); - LSL_BaseClass CompiledScript; - CompiledScript = m_scriptEngine.m_AppDomainManager.LoadScript(ScriptSource); - -#if DEBUG - Console.WriteLine("Script " + itemID + " occupies {0} bytes", GC.GetTotalMemory(true) - before); -#endif - - CompiledScript.SourceCode = ScriptSource; - // Add it to our script memstruct - SetScript(localID, itemID, CompiledScript); - - // We need to give (untrusted) assembly a private instance of BuiltIns - // this private copy will contain Read-Only FullitemID so that it can bring that on to the server whenever needed. - - - LSL_BuiltIn_Commands LSLB = new LSL_BuiltIn_Commands(m_scriptEngine, m_host, localID, itemID); - - // Start the script - giving it BuiltIns - CompiledScript.Start(LSLB); - - // Fire the first start-event - m_scriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "state_entry", new object[] {}); - } - catch (Exception e) - { - //m_scriptEngine.Log.Error("ScriptEngine", "Error compiling script: " + e.ToString()); try { - // DISPLAY ERROR INWORLD - string text = "Error compiling script:\r\n" + e.Message.ToString(); - if (text.Length > 1500) - text = text.Substring(0, 1500); - World.SimChat(Helpers.StringToField(text), 1, 0, m_host.AbsolutePosition, m_host.Name, m_host.UUID); + + // Compile (We assume LSL) + ScriptSource = LSLCompiler.CompileFromLSLText(Script); + //Console.WriteLine("Compilation of " + FileName + " done"); + // * Insert yield into code + ScriptSource = ProcessYield(ScriptSource); + + +#if DEBUG + long before; + before = GC.GetTotalMemory(true); +#endif + + LSL_BaseClass CompiledScript; + CompiledScript = m_scriptEngine.m_AppDomainManager.LoadScript(ScriptSource); + +#if DEBUG + Console.WriteLine("Script " + itemID + " occupies {0} bytes", GC.GetTotalMemory(true) - before); +#endif + + CompiledScript.SourceCode = ScriptSource; + // Add it to our script memstruct + SetScript(localID, itemID, CompiledScript); + + // We need to give (untrusted) assembly a private instance of BuiltIns + // this private copy will contain Read-Only FullitemID so that it can bring that on to the server whenever needed. + + + LSL_BuiltIn_Commands LSLB = new LSL_BuiltIn_Commands(m_scriptEngine, m_host, localID, itemID); + + // Start the script - giving it BuiltIns + CompiledScript.Start(LSLB); + + // Fire the first start-event + m_scriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "state_entry", new object[] { }); } - catch (Exception e2) + catch (Exception e) { - m_scriptEngine.Log.Error("ScriptEngine", "Error displaying error in-world: " + e2.ToString()); + //m_scriptEngine.Log.Error("ScriptEngine", "Error compiling script: " + e.ToString()); + try + { + // DISPLAY ERROR INWORLD + string text = "Error compiling script:\r\n" + e.Message.ToString(); + if (text.Length > 1500) + text = text.Substring(0, 1500); + World.SimChat(Helpers.StringToField(text), 1, 0, m_host.AbsolutePosition, m_host.Name, m_host.UUID); + } + catch (Exception e2) + { + m_scriptEngine.Log.Error("ScriptEngine", "Error displaying error in-world: " + e2.ToString()); + m_scriptEngine.Log.Error("ScriptEngine", "Errormessage: Error compiling script:\r\n" + e.Message.ToString()); + } } } } private void _StopScript(uint localID, LLUUID itemID) { + lock (startStopLock) + { // Stop script Console.WriteLine("Stop script localID: " + localID + " LLUID: " + itemID.ToString()); @@ -361,6 +370,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine ": " + e.ToString()); } } + } private string ProcessYield(string FileName) { @@ -382,12 +392,18 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine /// Arguments to pass to function internal void ExecuteEvent(uint localID, LLUUID itemID, string FunctionName, object[] args) { +#if DEBUG + Console.WriteLine("ScriptEngine: Inside ExecuteEvent for event " + FunctionName); +#endif // Execute a function in the script //m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function localID: " + localID + ", itemID: " + itemID + ", FunctionName: " + FunctionName); LSL_BaseClass Script = m_scriptEngine.m_ScriptManager.GetScript(localID, itemID); if (Script == null) return; +#if DEBUG + Console.WriteLine("ScriptEngine: Executing event: " + FunctionName); +#endif // Must be done in correct AppDomain, so leaving it up to the script itself Script.Exec.ExecuteEvent(FunctionName, args); } diff --git a/prebuild.xml b/prebuild.xml index ddf90ab2f5..5d83c5a6ec 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -963,61 +963,6 @@ - - - - ../../../../bin/ - - - - - ../../../../bin/ - - - - ../../../../bin/ - ../../../../bin/ScriptEngines/ - - - - - - - - - - - - - - ../../../../bin/ScriptEngines/ - - - - - ../../../../bin/ScriptEngines/ - - - - ../../../../bin/ - ../../../../bin/ScriptEngines/ - - - - - - - - - - - - - - - - -