From 9c8aeff27c503beedc2e8566a4a7401dfe3fd15d Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Sun, 21 Sep 2008 00:42:27 +0000 Subject: Some error handling to avoid errors in SEC --- .../ScriptEngine/RegionScriptEngineBase.cs | 45 ++++++++++++++-------- .../ScriptEngine/RegionScriptEnginePlugin.cs | 13 ++++++- 2 files changed, 40 insertions(+), 18 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs b/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs index c0a37a0..e6f5210 100644 --- a/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs +++ b/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEngineBase.cs @@ -72,21 +72,25 @@ namespace OpenSim.ApplicationPlugins.ScriptEngine foreach (string c in ComponentList) { m_log.Info("[" + Name + "]: Loading: " + c); - try - { - if (ComponentRegistry.providers.ContainsKey(c)) - Components.Add(Activator.CreateInstance(ComponentRegistry.providers[c]) as ComponentBase); - else - m_log.Error("[" + Name + "]: Component \"" + c + "\" not found, can not load"); - } catch (Exception ex) + lock (Components) { - m_log.Error("[" + Name + "]: Exception loading \"" + c + "\": " + ex.ToString()); + try + { + if (ComponentRegistry.providers.ContainsKey(c)) + Components.Add(Activator.CreateInstance(ComponentRegistry.providers[c]) as ComponentBase); + else + m_log.Error("[" + Name + "]: Component \"" + c + "\" not found, can not load"); + } + catch (Exception ex) + { + m_log.Error("[" + Name + "]: Exception loading \"" + c + "\": " + ex.ToString()); + } } } - + // Run Initialize on all our providers, hand over a reference of ourself. - foreach (ComponentBase p in Components) + foreach (ComponentBase p in Components.ToArray()) { try { @@ -94,12 +98,17 @@ namespace OpenSim.ApplicationPlugins.ScriptEngine } catch (Exception ex) { - m_log.Error("[" + Name + "]: Error initializing \"" + p.GetType().FullName + "\": " + ex.ToString()); - Components.Remove(p); + lock (Components) + { + m_log.Error("[" + Name + "]: Error initializing \"" + p.GetType().FullName + "\": " + + ex.ToString()); + if (Components.Contains(p)) + Components.Remove(p); + } } } // All modules has been initialized, call Start() on them. - foreach (ComponentBase p in Components) + foreach (ComponentBase p in Components.ToArray()) { try { @@ -107,8 +116,12 @@ namespace OpenSim.ApplicationPlugins.ScriptEngine } catch (Exception ex) { - m_log.Error("[" + Name + "]: Error starting \"" + p.GetType().FullName + "\": " + ex.ToString()); - Components.Remove(p); + lock (Components) + { + m_log.Error("[" + Name + "]: Error starting \"" + p.GetType().FullName + "\": " + ex.ToString()); + if (Components.Contains(p)) + Components.Remove(p); + } } } @@ -149,7 +162,7 @@ namespace OpenSim.ApplicationPlugins.ScriptEngine PreClose(); // Then Call Close() on all components - foreach (ComponentBase p in Components) + foreach (ComponentBase p in Components.ToArray()) { try { diff --git a/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEnginePlugin.cs b/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEnginePlugin.cs index a0622ea..c4f4bbe 100644 --- a/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEnginePlugin.cs +++ b/OpenSim/ApplicationPlugins/ScriptEngine/RegionScriptEnginePlugin.cs @@ -45,8 +45,17 @@ namespace OpenSim.ApplicationPlugins.ScriptEngine { // New region is being created // Create a new script engine - scriptEngine = Activator.CreateInstance(ComponentRegistry.scriptEngines[tempScriptEngineName]) as RegionScriptEngineBase; - scriptEngine.Initialize(scene, source); + try + { + scriptEngine = + Activator.CreateInstance(ComponentRegistry.scriptEngines[tempScriptEngineName]) as + RegionScriptEngineBase; + scriptEngine.Initialize(scene, source); + } + catch (Exception ex) + { + scriptEngine.m_log.Error("[ScriptEngine]: Unable to load engine \"" + tempScriptEngineName + "\": " + ex.ToString()); + } } public void PostInitialise() -- cgit v1.1