On a multi-region simulator when AppDomain = true, make sure the DLL from the appropriate script engines subdir is loaded rather than always that of the first engine to load the DLL.

This resolves a DLL load failure on my Linux box when an attachment script was present on another region before the avatar arrived.
0.8.1-post-fixes
Justin Clark-Casey (justincc) 2015-01-26 23:16:06 +00:00
parent e26ba505f6
commit 1bed3aff0b
4 changed files with 147 additions and 91 deletions

View File

@ -291,7 +291,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
string source, string asset, UUID ownerUUID, bool alwaysRecompile,
out string assembly, out Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap)
{
// m_log.DebugFormat("[Compiler]: Compiling script\n{0}", Script);
// m_log.DebugFormat("[Compiler]: Checking script for asset {0} in {1}\n{2}", asset, m_scriptEngine.World.Name, source);
IScriptModuleComms comms = m_scriptEngine.World.RequestModuleInterface<IScriptModuleComms>();
@ -300,12 +300,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
assembly = GetCompilerOutput(asset);
// m_log.DebugFormat("[Compiler]: Retrieved assembly {0} for asset {1} in {2}", assembly, asset, m_scriptEngine.World.Name);
CheckOrCreateScriptsDirectory();
// Don't recompile if we're not forced to and we already have it
// Performing 3 file exists tests for every script can still be slow
if (!alwaysRecompile && File.Exists(assembly) && File.Exists(assembly + ".text") && File.Exists(assembly + ".map"))
{
// m_log.DebugFormat("[Compiler]: Found existing assembly {0} for asset {1} in {2}", assembly, asset, m_scriptEngine.World.Name);
// If we have already read this linemap file, then it will be in our dictionary.
// Don't build another copy of the dictionary (saves memory) and certainly
// don't keep reading the same file from disk multiple times.
@ -315,6 +319,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
return;
}
// m_log.DebugFormat("[Compiler]: Compiling assembly {0} for asset {1} in {2}", assembly, asset, m_scriptEngine.World.Name);
if (source == String.Empty)
throw new Exception("Cannot find script assembly and no script text present");

View File

@ -259,65 +259,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
/// </param>
/// <param name='stateSource'></param>
/// <returns>false if load failed, true if suceeded</returns>
public bool Load(AppDomain dom, Assembly scriptAssembly, string dataPath, StateSource stateSource)
public bool Load(
IScript script, EventWaitHandle coopSleepHandle, string assemblyPath,
string dataPath, StateSource stateSource, bool coopTermination)
{
m_assemblyPath = scriptAssembly.Location;
m_Script = script;
m_coopSleepHandle = coopSleepHandle;
m_assemblyPath = assemblyPath;
m_dataPath = dataPath;
m_stateSource = stateSource;
try
{
object[] constructorParams;
Type scriptType = scriptAssembly.GetType("SecondLife.XEngineScript");
if (scriptType != null)
{
m_coopTermination = true;
m_coopSleepHandle = new XEngineEventWaitHandle(false, EventResetMode.AutoReset);
constructorParams = new object[] { m_coopSleepHandle };
}
else
{
m_coopTermination = false;
scriptType = scriptAssembly.GetType("SecondLife.Script");
constructorParams = null;
}
if (dom != System.AppDomain.CurrentDomain)
m_Script
= (IScript)dom.CreateInstanceAndUnwrap(
Path.GetFileNameWithoutExtension(m_assemblyPath),
scriptType.FullName,
false,
BindingFlags.Default,
null,
constructorParams,
null,
null,
null);
else
m_Script
= (IScript)scriptAssembly.CreateInstance(
scriptType.FullName,
false,
BindingFlags.Default,
null,
constructorParams,
null,
null);
//ILease lease = (ILease)RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass);
//RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass);
// lease.Register(this);
}
catch (Exception e)
{
m_log.ErrorFormat(
"[SCRIPT INSTANCE]: Not starting script {0} (id {1}) in part {2} (id {3}) in object {4} in {5}. Error loading assembly {6}. Exception {7}{8}",
ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, Engine.World.Name, scriptAssembly.Location, e.Message, e.StackTrace);
return false;
}
m_coopTermination = coopTermination;
ApiManager am = new ApiManager();

View File

@ -76,6 +76,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance.Tests
//AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory + "/bin");
// Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
m_xEngine = new OpenSim.Region.ScriptEngine.XEngine.XEngine();
m_xEngine.DebugLevel = 1;
IniConfigSource configSource = new IniConfigSource();
@ -336,7 +337,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance.Tests
public void TestStopOnInfiniteJumpLoop()
{
TestHelpers.InMethod();
// TestHelpers.EnableLogging();
TestHelpers.EnableLogging();
string script =
@"default

View File

@ -1327,23 +1327,117 @@ namespace OpenSim.Region.ScriptEngine.XEngine
}
m_DomainScripts[appDomain].Add(itemID);
Assembly scriptAssembly = m_AppDomains[appDomain].Load(Path.GetFileNameWithoutExtension(assemblyPath));
IScript scriptObj = null;
bool recompile = false;
bool abortAfterRecompile = false;
EventWaitHandle coopSleepHandle = null;
bool coopTerminationForThisScript;
string typeName;
// Set up assembly name to point to the appropriate scriptEngines directory
AssemblyName assemblyName = new AssemblyName(Path.GetFileNameWithoutExtension(assemblyPath));
assemblyName.CodeBase = Path.GetDirectoryName(assemblyPath);
if (m_coopTermination)
{
Type scriptType = scriptAssembly.GetType("SecondLife.XEngineScript");
try
{
coopSleepHandle = new XEngineEventWaitHandle(false, EventResetMode.AutoReset);
if (scriptType == null)
scriptObj
= (IScript)m_AppDomains[appDomain].CreateInstanceAndUnwrap(
assemblyName.FullName,
"SecondLife.XEngineScript",
false,
BindingFlags.Default,
null,
new object[] { coopSleepHandle },
null,
null);
coopTerminationForThisScript = true;
}
catch (TypeLoadException e)
{
coopSleepHandle = null;
try
{
scriptObj
= (IScript)m_AppDomains[appDomain].CreateInstanceAndUnwrap(
assemblyName.FullName,
"SecondLife.Script",
false,
BindingFlags.Default,
null,
null,
null,
null);
}
catch (Exception e2)
{
m_log.Error(
string.Format(
"[XENGINE]: Could not load previous SecondLife.Script from assembly {0} in {1}. Recompiling then aborting. Exception ",
assemblyName.FullName, World.Name),
e2);
abortAfterRecompile = true;
}
coopTerminationForThisScript = false;
recompile = true;
}
}
else
{
Type scriptType = scriptAssembly.GetType("SecondLife.Script");
try
{
scriptObj
= (IScript)m_AppDomains[appDomain].CreateInstanceAndUnwrap(
assemblyName.FullName,
"SecondLife.Script",
false,
BindingFlags.Default,
null,
null,
null,
null);
if (scriptType == null)
coopTerminationForThisScript = false;
}
catch (TypeLoadException e)
{
coopSleepHandle = new XEngineEventWaitHandle(false, EventResetMode.AutoReset);
try
{
scriptObj
= (IScript)m_AppDomains[appDomain].CreateInstanceAndUnwrap(
assemblyName.FullName,
"SecondLife.XEngineScript",
false,
BindingFlags.Default,
null,
new object[] { new XEngineEventWaitHandle(false, EventResetMode.AutoReset) },
null,
null);
}
catch (Exception e2)
{
m_log.Error(
string.Format(
"[XENGINE]: Could not load previous SecondLife.XEngineScript from assembly {0} in {1}. Recompiling then aborting. Exception ",
assemblyName.FullName, World.Name),
e2);
abortAfterRecompile = true;
}
coopTerminationForThisScript = true;
recompile = true;
}
}
// If we are loading all scripts into the same AppDomain, then we can't reload the DLL in this
// simulator session if the script halt strategy has been changed. Instead, we'll continue with
@ -1351,12 +1445,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine
if (recompile)
{
m_log.DebugFormat(
"[XEngine]: Recompiling script {0}.{1}, item UUID {2}, prim UUID {3} @ {4}.{5} to switch it to {6} termination. Will be active on next restart.",
"[XEngine]: Recompiling script {0}.{1}, item UUID {2}, prim UUID {3} @ {4}.{5} to switch it to {6} termination. New termination will be active on next restart.",
part.ParentGroup.RootPart.Name, item.Name, itemID, part.UUID,
part.ParentGroup.RootPart.AbsolutePosition, part.ParentGroup.Scene.Name,
m_coopTermination ? "co-op" : "abort");
m_Compiler.PerformScriptCompile(script, assetID.ToString(), item.OwnerID, true, out assemblyPath, out linemap);
if (abortAfterRecompile)
return false;
}
instance = new ScriptInstance(this, part,
@ -1364,9 +1461,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
startParam, postOnRez,
m_MaxScriptQueue);
if (!instance.Load(
m_AppDomains[appDomain], scriptAssembly,
Path.Combine(ScriptEnginePath, World.RegionInfo.RegionID.ToString()), stateSource))
if (
!instance.Load(
scriptObj, coopSleepHandle, assemblyPath,
Path.Combine(ScriptEnginePath, World.RegionInfo.RegionID.ToString()), stateSource, coopTerminationForThisScript))
return false;
// if (DebugLevel >= 1)