Merge pull request #1 from zhu-rengong/fix_leakage
Fix leakage of the dynamic assembly and unable to unloaded immediately.
This commit is contained in:
@@ -144,5 +144,14 @@ namespace Barotrauma
|
|||||||
return files.ToArray();
|
return files.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
Assembly = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
~CsScriptLoader()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ using Microsoft.CodeAnalysis;
|
|||||||
using System.Runtime.Loader;
|
using System.Runtime.Loader;
|
||||||
using System.Reflection.PortableExecutable;
|
using System.Reflection.PortableExecutable;
|
||||||
using System.Reflection.Metadata;
|
using System.Reflection.Metadata;
|
||||||
|
using MoonSharp.Interpreter;
|
||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
@@ -97,7 +98,11 @@ namespace Barotrauma
|
|||||||
if (runner != null)
|
if (runner != null)
|
||||||
{
|
{
|
||||||
var method = runner.GetType().GetMethod("Run", BindingFlags.Public | BindingFlags.Instance);
|
var method = runner.GetType().GetMethod("Run", BindingFlags.Public | BindingFlags.Instance);
|
||||||
if (method != null) scriptResilt = method.Invoke(runner, null);
|
if (method != null)
|
||||||
|
{
|
||||||
|
scriptResilt = method.Invoke(runner, null);
|
||||||
|
foreach (var type in assembly.GetTypes()) { UserData.UnregisterType(type, true); }
|
||||||
|
}
|
||||||
else LuaCsSetup.PrintCsError("Script Error - no run method detected");
|
else LuaCsSetup.PrintCsError("Script Error - no run method detected");
|
||||||
}
|
}
|
||||||
else LuaCsSetup.PrintCsError("Script Error - no runner class detected");
|
else LuaCsSetup.PrintCsError("Script Error - no runner class detected");
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
var type = Type.GetType(typeName);
|
var type = Type.GetType(typeName);
|
||||||
if (type != null) return type;
|
if (type != null) return type;
|
||||||
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
|
foreach (var a in AppDomain.CurrentDomain.GetAssemblies().Reverse())
|
||||||
{
|
{
|
||||||
type = a.GetType(typeName);
|
type = a.GetType(typeName);
|
||||||
if (type != null)
|
if (type != null)
|
||||||
|
|||||||
@@ -278,6 +278,10 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
|
foreach (var type in AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "NetScriptAssembly").SelectMany(assembly => assembly.GetTypes()))
|
||||||
|
{
|
||||||
|
UserData.UnregisterType(type, true);
|
||||||
|
}
|
||||||
foreach (var mod in ACsMod.LoadedMods.ToArray()) mod.Dispose();
|
foreach (var mod in ACsMod.LoadedMods.ToArray()) mod.Dispose();
|
||||||
ACsMod.LoadedMods.Clear();
|
ACsMod.LoadedMods.Clear();
|
||||||
Hook?.Call("stop");
|
Hook?.Call("stop");
|
||||||
@@ -289,8 +293,18 @@ namespace Barotrauma
|
|||||||
Game = new LuaGame();
|
Game = new LuaGame();
|
||||||
Networking = new LuaCsNetworking();
|
Networking = new LuaCsNetworking();
|
||||||
LuaScriptLoader = null;
|
LuaScriptLoader = null;
|
||||||
|
lua = null;
|
||||||
Lua = null;
|
Lua = null;
|
||||||
CsScript = null;
|
CsScript = null;
|
||||||
|
|
||||||
|
if (CsScriptLoader != null)
|
||||||
|
{
|
||||||
|
CsScriptLoader.Clear();
|
||||||
|
CsScriptLoader.Unload();
|
||||||
|
CsScriptLoader = null;
|
||||||
|
GC.Collect();
|
||||||
|
GC.WaitForPendingFinalizers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
|
|||||||
Reference in New Issue
Block a user