From efcf00ee60c48b81d88ea48e31162e4fd97575f5 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Thu, 5 Feb 2009 16:12:51 +0000 Subject: From: Christopher Yeoh This patch fixes the problem where if an object containing a script is deleted at the same time as an object containing the same script is rezzed, it can result in the assembly file being deleted after the second object script initialisation has found it but not started using it yet, resulting in the script not starting up. --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 63 +++++++++++++++++++------- 1 file changed, 46 insertions(+), 17 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 7a52205..f0f867b 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -100,6 +100,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine private Dictionary m_Assemblies = new Dictionary(); + private Dictionary m_AddingAssemblies = + new Dictionary(); + // This will list AppDomains by script asset private Dictionary m_AppDomains = @@ -509,8 +512,16 @@ namespace OpenSim.Region.ScriptEngine.XEngine try { - assembly = m_Compiler.PerformScriptCompile(script, - assetID.ToString()); + lock (m_AddingAssemblies) + { + assembly = m_Compiler.PerformScriptCompile(script, + assetID.ToString()); + if (!m_AddingAssemblies.ContainsKey(assembly)) { + m_AddingAssemblies[assembly] = 1; + } else { + m_AddingAssemblies[assembly]++; + } + } } catch (Exception e) { @@ -592,6 +603,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine m_log.ErrorFormat("[XEngine] Exception creating app domain:\n {0}", e.ToString()); m_ScriptErrorMessage += "Exception creating app domain:\n"; m_ScriptFailCount++; + lock (m_AddingAssemblies) + { + m_AddingAssemblies[assembly]--; + } return false; } } @@ -626,6 +641,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine if (!m_Assemblies.ContainsKey(assetID)) m_Assemblies[assetID] = assembly; + lock (m_AddingAssemblies) + { + m_AddingAssemblies[assembly]--; + } + if (instance!=null) instance.Init(); } @@ -710,24 +730,33 @@ namespace OpenSim.Region.ScriptEngine.XEngine assetIDList.Remove(i.AssetID); } - foreach (UUID assetID in assetIDList) + lock (m_AddingAssemblies) { -// m_log.DebugFormat("[XEngine] Removing unreferenced assembly {0}", m_Assemblies[assetID]); - try - { - if (File.Exists(m_Assemblies[assetID])) - File.Delete(m_Assemblies[assetID]); - - if (File.Exists(m_Assemblies[assetID]+".state")) - File.Delete(m_Assemblies[assetID]+".state"); - - if (File.Exists(m_Assemblies[assetID]+".mdb")) - File.Delete(m_Assemblies[assetID]+".mdb"); - } - catch (Exception) + foreach (UUID assetID in assetIDList) { + // Do not remove assembly files if another instance of the script + // is currently initialising + if (!m_AddingAssemblies.ContainsKey(m_Assemblies[assetID]) + || m_AddingAssemblies[m_Assemblies[assetID]] == 0) + { +// m_log.DebugFormat("[XEngine] Removing unreferenced assembly {0}", m_Assemblies[assetID]); + try + { + if (File.Exists(m_Assemblies[assetID])) + File.Delete(m_Assemblies[assetID]); + + if (File.Exists(m_Assemblies[assetID]+".state")) + File.Delete(m_Assemblies[assetID]+".state"); + + if (File.Exists(m_Assemblies[assetID]+".mdb")) + File.Delete(m_Assemblies[assetID]+".mdb"); + } + catch (Exception) + { + } + m_Assemblies.Remove(assetID); + } } - m_Assemblies.Remove(assetID); } } -- cgit v1.1