diff options
author | Tedd Hansen | 2007-11-01 19:27:03 +0000 |
---|---|---|
committer | Tedd Hansen | 2007-11-01 19:27:03 +0000 |
commit | dcf41cb68370dc1e1b03fd78edf75b175b17f6ea (patch) | |
tree | 3b2079c88657beee8380cdd6acebd33a1891cc15 /OpenSim | |
parent | * Diuerse beavtificatems (diff) | |
download | opensim-SC-dcf41cb68370dc1e1b03fd78edf75b175b17f6ea.zip opensim-SC-dcf41cb68370dc1e1b03fd78edf75b175b17f6ea.tar.gz opensim-SC-dcf41cb68370dc1e1b03fd78edf75b175b17f6ea.tar.bz2 opensim-SC-dcf41cb68370dc1e1b03fd78edf75b175b17f6ea.tar.xz |
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.
Diffstat (limited to 'OpenSim')
5 files changed, 87 insertions, 52 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/Executor.cs b/OpenSim/Region/ScriptEngine/Common/Executor.cs index c656e01..1805e38 100644 --- a/OpenSim/Region/ScriptEngine/Common/Executor.cs +++ b/OpenSim/Region/ScriptEngine/Common/Executor.cs | |||
@@ -82,6 +82,10 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
82 | 82 | ||
83 | string EventName = m_Script.State() + "_event_" + FunctionName; | 83 | string EventName = m_Script.State() + "_event_" + FunctionName; |
84 | 84 | ||
85 | #if DEBUG | ||
86 | Console.WriteLine("ScriptEngine: Script event function name: " + EventName); | ||
87 | #endif | ||
88 | |||
85 | //type.InvokeMember(EventName, BindingFlags.InvokeMethod, null, m_Script, args); | 89 | //type.InvokeMember(EventName, BindingFlags.InvokeMethod, null, m_Script, args); |
86 | 90 | ||
87 | //Console.WriteLine("ScriptEngine Executor.ExecuteEvent: \"" + EventName + "\""); | 91 | //Console.WriteLine("ScriptEngine Executor.ExecuteEvent: \"" + EventName + "\""); |
@@ -112,6 +116,9 @@ namespace OpenSim.Region.ScriptEngine.Common | |||
112 | return; | 116 | return; |
113 | } | 117 | } |
114 | 118 | ||
119 | #if DEBUG | ||
120 | Console.WriteLine("ScriptEngine: Executing function name: " + EventName); | ||
121 | #endif | ||
115 | // Found | 122 | // Found |
116 | //try | 123 | //try |
117 | //{ | 124 | //{ |
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/Compiler.cs index 7f452e0..c81e6bd 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 | |||
39 | private LSL2CSConverter LSL_Converter = new LSL2CSConverter(); | 39 | private LSL2CSConverter LSL_Converter = new LSL2CSConverter(); |
40 | private CSharpCodeProvider codeProvider = new CSharpCodeProvider(); | 40 | private CSharpCodeProvider codeProvider = new CSharpCodeProvider(); |
41 | private static UInt64 scriptCompileCounter = 0; | 41 | private static UInt64 scriptCompileCounter = 0; |
42 | private static int instanceID = new Random().Next(0, int.MaxValue); // Implemented due to peer preassure --- will cause garbage in ScriptEngines folder ;) | ||
42 | //private ICodeCompiler icc = codeProvider.CreateCompiler(); | 43 | //private ICodeCompiler icc = codeProvider.CreateCompiler(); |
43 | public string CompileFromFile(string LSOFileName) | 44 | public string CompileFromFile(string LSOFileName) |
44 | { | 45 | { |
@@ -82,7 +83,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
82 | { | 83 | { |
83 | // Output assembly name | 84 | // Output assembly name |
84 | scriptCompileCounter++; | 85 | scriptCompileCounter++; |
85 | string OutFile = Path.Combine("ScriptEngines", "Script_" + scriptCompileCounter + ".dll"); | 86 | string OutFile = Path.Combine("ScriptEngines", "DotNetScript_" + instanceID.ToString() + "_" + scriptCompileCounter.ToString() + ".dll"); |
86 | try | 87 | try |
87 | { | 88 | { |
88 | File.Delete(OutFile); | 89 | File.Delete(OutFile); |
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs index 0c28617..bbd6839 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 | |||
53 | 53 | ||
54 | public string Convert(string Script) | 54 | public string Convert(string Script) |
55 | { | 55 | { |
56 | quotes.Clear(); | ||
56 | string Return = ""; | 57 | string Return = ""; |
57 | Script = " \r\n" + Script; | 58 | Script = " \r\n" + Script; |
58 | 59 | ||
@@ -310,6 +311,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL | |||
310 | Return += Script; | 311 | Return += Script; |
311 | Return += "} }\r\n"; | 312 | Return += "} }\r\n"; |
312 | 313 | ||
314 | |||
315 | quotes.Clear(); | ||
316 | |||
313 | return Return; | 317 | return Return; |
314 | } | 318 | } |
315 | } | 319 | } |
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs index d7491d9..f215dd5 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs | |||
@@ -181,6 +181,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
181 | // Execute function | 181 | // Execute function |
182 | try | 182 | try |
183 | { | 183 | { |
184 | #if DEBUG | ||
185 | m_ScriptEngine.Log.Debug("ScriptEngine", "Executing event:\r\n" | ||
186 | + "QIS.localID: " + QIS.localID | ||
187 | + ", QIS.itemID: " + QIS.itemID | ||
188 | + ", QIS.functionName: " + QIS.functionName); | ||
189 | #endif | ||
184 | m_ScriptEngine.m_ScriptManager.ExecuteEvent(QIS.localID, QIS.itemID, | 190 | m_ScriptEngine.m_ScriptManager.ExecuteEvent(QIS.localID, QIS.itemID, |
185 | QIS.functionName, QIS.param); | 191 | QIS.functionName, QIS.param); |
186 | } | 192 | } |
@@ -188,16 +194,17 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
188 | { | 194 | { |
189 | // DISPLAY ERROR INWORLD | 195 | // DISPLAY ERROR INWORLD |
190 | string text = "Error executing script function \"" + QIS.functionName + "\":\r\n"; | 196 | string text = "Error executing script function \"" + QIS.functionName + "\":\r\n"; |
191 | if (e.InnerException != null) | 197 | //if (e.InnerException != null) |
192 | { | 198 | //{ |
193 | // Send inner exception | 199 | // Send inner exception |
194 | text += e.InnerException.Message.ToString(); | 200 | text += e.InnerException.Message.ToString(); |
195 | } | 201 | //} |
196 | else | 202 | //else |
197 | { | 203 | //{ |
204 | text += "\r\n"; | ||
198 | // Send normal | 205 | // Send normal |
199 | text += e.Message.ToString(); | 206 | text += e.Message.ToString(); |
200 | } | 207 | //} |
201 | try | 208 | try |
202 | { | 209 | { |
203 | if (text.Length > 1500) | 210 | if (text.Length > 1500) |
@@ -214,7 +221,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
214 | //else | 221 | //else |
215 | //{ | 222 | //{ |
216 | // T oconsole | 223 | // T oconsole |
217 | Console.WriteLine("Unable to send text in-world:\r\n" + text); | 224 | m_ScriptEngine.Log.Error("ScriptEngine", "Unable to send text in-world:\r\n" + text); |
218 | } | 225 | } |
219 | } | 226 | } |
220 | finally | 227 | finally |
@@ -230,7 +237,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
230 | } | 237 | } |
231 | catch (Exception e) | 238 | catch (Exception e) |
232 | { | 239 | { |
233 | Console.WriteLine("Exception in EventQueueThreadLoop: " + e.ToString()); | 240 | m_ScriptEngine.Log.Error("ScriptEngine", "Exception in EventQueueThreadLoop: " + e.ToString()); |
234 | } | 241 | } |
235 | } // while | 242 | } // while |
236 | } // try | 243 | } // try |
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs index 54a5ef5..a3cf9f7 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs | |||
@@ -225,6 +225,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
225 | 225 | ||
226 | #region Start/Stop/Reset script | 226 | #region Start/Stop/Reset script |
227 | 227 | ||
228 | Object startStopLock = new Object(); | ||
229 | |||
228 | /// <summary> | 230 | /// <summary> |
229 | /// Fetches, loads and hooks up a script to an objects events | 231 | /// Fetches, loads and hooks up a script to an objects events |
230 | /// </summary> | 232 | /// </summary> |
@@ -259,76 +261,83 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
259 | StartScript(localID, itemID, script); | 261 | StartScript(localID, itemID, script); |
260 | } | 262 | } |
261 | 263 | ||
264 | // Create a new instance of the compiler (reuse) | ||
265 | Compiler.LSL.Compiler LSLCompiler = new Compiler.LSL.Compiler(); | ||
262 | private void _StartScript(uint localID, LLUUID itemID, string Script) | 266 | private void _StartScript(uint localID, LLUUID itemID, string Script) |
263 | { | 267 | { |
264 | //IScriptHost root = host.GetRoot(); | 268 | lock (startStopLock) |
265 | Console.WriteLine("ScriptManager StartScript: localID: " + localID + ", itemID: " + itemID); | 269 | { |
270 | //IScriptHost root = host.GetRoot(); | ||
271 | Console.WriteLine("ScriptManager StartScript: localID: " + localID + ", itemID: " + itemID); | ||
266 | 272 | ||
267 | // We will initialize and start the script. | 273 | // We will initialize and start the script. |
268 | // It will be up to the script itself to hook up the correct events. | 274 | // It will be up to the script itself to hook up the correct events. |
269 | string ScriptSource = ""; | 275 | string ScriptSource = ""; |
270 | 276 | ||
271 | SceneObjectPart m_host = World.GetSceneObjectPart(localID); | 277 | SceneObjectPart m_host = World.GetSceneObjectPart(localID); |
272 | 278 | ||
273 | try | 279 | try |
274 | { | 280 | { |
275 | // Create a new instance of the compiler (currently we don't want reuse) | 281 | |
276 | Compiler.LSL.Compiler LSLCompiler = new Compiler.LSL.Compiler(); | 282 | // Compile (We assume LSL) |
277 | // Compile (We assume LSL) | 283 | ScriptSource = LSLCompiler.CompileFromLSLText(Script); |
278 | ScriptSource = LSLCompiler.CompileFromLSLText(Script); | 284 | //Console.WriteLine("Compilation of " + FileName + " done"); |
279 | //Console.WriteLine("Compilation of " + FileName + " done"); | 285 | // * Insert yield into code |
280 | // * Insert yield into code | 286 | ScriptSource = ProcessYield(ScriptSource); |
281 | ScriptSource = ProcessYield(ScriptSource); | ||
282 | 287 | ||
283 | 288 | ||
284 | #if DEBUG | 289 | #if DEBUG |
285 | long before; | 290 | long before; |
286 | before = GC.GetTotalMemory(true); | 291 | before = GC.GetTotalMemory(true); |
287 | #endif | 292 | #endif |
288 | 293 | ||
289 | LSL_BaseClass CompiledScript; | 294 | LSL_BaseClass CompiledScript; |
290 | CompiledScript = m_scriptEngine.m_AppDomainManager.LoadScript(ScriptSource); | 295 | CompiledScript = m_scriptEngine.m_AppDomainManager.LoadScript(ScriptSource); |
291 | 296 | ||
292 | #if DEBUG | 297 | #if DEBUG |
293 | Console.WriteLine("Script " + itemID + " occupies {0} bytes", GC.GetTotalMemory(true) - before); | 298 | Console.WriteLine("Script " + itemID + " occupies {0} bytes", GC.GetTotalMemory(true) - before); |
294 | #endif | 299 | #endif |
295 | 300 | ||
296 | CompiledScript.SourceCode = ScriptSource; | 301 | CompiledScript.SourceCode = ScriptSource; |
297 | // Add it to our script memstruct | 302 | // Add it to our script memstruct |
298 | SetScript(localID, itemID, CompiledScript); | 303 | SetScript(localID, itemID, CompiledScript); |
299 | 304 | ||
300 | // We need to give (untrusted) assembly a private instance of BuiltIns | 305 | // We need to give (untrusted) assembly a private instance of BuiltIns |
301 | // this private copy will contain Read-Only FullitemID so that it can bring that on to the server whenever needed. | 306 | // this private copy will contain Read-Only FullitemID so that it can bring that on to the server whenever needed. |
302 | 307 | ||
303 | 308 | ||
304 | LSL_BuiltIn_Commands LSLB = new LSL_BuiltIn_Commands(m_scriptEngine, m_host, localID, itemID); | 309 | LSL_BuiltIn_Commands LSLB = new LSL_BuiltIn_Commands(m_scriptEngine, m_host, localID, itemID); |
305 | 310 | ||
306 | // Start the script - giving it BuiltIns | 311 | // Start the script - giving it BuiltIns |
307 | CompiledScript.Start(LSLB); | 312 | CompiledScript.Start(LSLB); |
308 | 313 | ||
309 | // Fire the first start-event | 314 | // Fire the first start-event |
310 | m_scriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "state_entry", new object[] {}); | 315 | m_scriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "state_entry", new object[] { }); |
311 | } | ||
312 | catch (Exception e) | ||
313 | { | ||
314 | //m_scriptEngine.Log.Error("ScriptEngine", "Error compiling script: " + e.ToString()); | ||
315 | try | ||
316 | { | ||
317 | // DISPLAY ERROR INWORLD | ||
318 | string text = "Error compiling script:\r\n" + e.Message.ToString(); | ||
319 | if (text.Length > 1500) | ||
320 | text = text.Substring(0, 1500); | ||
321 | World.SimChat(Helpers.StringToField(text), 1, 0, m_host.AbsolutePosition, m_host.Name, m_host.UUID); | ||
322 | } | 316 | } |
323 | catch (Exception e2) | 317 | catch (Exception e) |
324 | { | 318 | { |
325 | m_scriptEngine.Log.Error("ScriptEngine", "Error displaying error in-world: " + e2.ToString()); | 319 | //m_scriptEngine.Log.Error("ScriptEngine", "Error compiling script: " + e.ToString()); |
320 | try | ||
321 | { | ||
322 | // DISPLAY ERROR INWORLD | ||
323 | string text = "Error compiling script:\r\n" + e.Message.ToString(); | ||
324 | if (text.Length > 1500) | ||
325 | text = text.Substring(0, 1500); | ||
326 | World.SimChat(Helpers.StringToField(text), 1, 0, m_host.AbsolutePosition, m_host.Name, m_host.UUID); | ||
327 | } | ||
328 | catch (Exception e2) | ||
329 | { | ||
330 | m_scriptEngine.Log.Error("ScriptEngine", "Error displaying error in-world: " + e2.ToString()); | ||
331 | m_scriptEngine.Log.Error("ScriptEngine", "Errormessage: Error compiling script:\r\n" + e.Message.ToString()); | ||
332 | } | ||
326 | } | 333 | } |
327 | } | 334 | } |
328 | } | 335 | } |
329 | 336 | ||
330 | private void _StopScript(uint localID, LLUUID itemID) | 337 | private void _StopScript(uint localID, LLUUID itemID) |
331 | { | 338 | { |
339 | lock (startStopLock) | ||
340 | { | ||
332 | // Stop script | 341 | // Stop script |
333 | Console.WriteLine("Stop script localID: " + localID + " LLUID: " + itemID.ToString()); | 342 | Console.WriteLine("Stop script localID: " + localID + " LLUID: " + itemID.ToString()); |
334 | 343 | ||
@@ -361,6 +370,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
361 | ": " + e.ToString()); | 370 | ": " + e.ToString()); |
362 | } | 371 | } |
363 | } | 372 | } |
373 | } | ||
364 | 374 | ||
365 | private string ProcessYield(string FileName) | 375 | private string ProcessYield(string FileName) |
366 | { | 376 | { |
@@ -382,12 +392,18 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine | |||
382 | /// <param name="args">Arguments to pass to function</param> | 392 | /// <param name="args">Arguments to pass to function</param> |
383 | internal void ExecuteEvent(uint localID, LLUUID itemID, string FunctionName, object[] args) | 393 | internal void ExecuteEvent(uint localID, LLUUID itemID, string FunctionName, object[] args) |
384 | { | 394 | { |
395 | #if DEBUG | ||
396 | Console.WriteLine("ScriptEngine: Inside ExecuteEvent for event " + FunctionName); | ||
397 | #endif | ||
385 | // Execute a function in the script | 398 | // Execute a function in the script |
386 | //m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function localID: " + localID + ", itemID: " + itemID + ", FunctionName: " + FunctionName); | 399 | //m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function localID: " + localID + ", itemID: " + itemID + ", FunctionName: " + FunctionName); |
387 | LSL_BaseClass Script = m_scriptEngine.m_ScriptManager.GetScript(localID, itemID); | 400 | LSL_BaseClass Script = m_scriptEngine.m_ScriptManager.GetScript(localID, itemID); |
388 | if (Script == null) | 401 | if (Script == null) |
389 | return; | 402 | return; |
390 | 403 | ||
404 | #if DEBUG | ||
405 | Console.WriteLine("ScriptEngine: Executing event: " + FunctionName); | ||
406 | #endif | ||
391 | // Must be done in correct AppDomain, so leaving it up to the script itself | 407 | // Must be done in correct AppDomain, so leaving it up to the script itself |
392 | Script.Exec.ExecuteEvent(FunctionName, args); | 408 | Script.Exec.ExecuteEvent(FunctionName, args); |
393 | } | 409 | } |