Disable load context on server ContentStart.

This commit is contained in:
Pieter-Jan Briers
2020-05-31 01:19:00 +02:00
parent 486fd670e2
commit f9df2b141c
5 changed files with 18 additions and 4 deletions

View File

@@ -48,6 +48,10 @@ namespace Robust.Client
var gc = (GameController) IoCManager.Resolve<IGameController>();
gc.SetCommandLineArgs(args);
// When the game is ran with the startup executable being content,
// we have to disable the separate load context.
// Otherwise the content assemblies will be loaded twice which causes *many* fun bugs.
gc._disableAssemblyLoadContext = contentStart;
if (!gc.Startup())
{

View File

@@ -199,6 +199,8 @@ namespace Robust.Server
_resources.MountContentDirectory($@"{contentRootDir}Resources/");
#endif
_modLoader.SetUseLoadContext(!DisableLoadContext);
//identical code in game controller for client
if (!_modLoader.TryLoadAssembly<GameShared>(_resources, $"Content.Shared"))
{
@@ -292,6 +294,8 @@ namespace Robust.Server
_shutdownEvent.Set();
}
public bool DisableLoadContext { private get; set; }
public void OverrideMainLoop(IGameLoop gameLoop)
{
_mainLoop = gameLoop;

View File

@@ -7,7 +7,7 @@ namespace Robust.Server
#if FULL_RELEASE
throw new System.InvalidOperationException("ContentStart is not available on a full release.");
#else
Program.Main(args);
Program.Start(args, true);
#endif
}
}

View File

@@ -44,6 +44,8 @@ namespace Robust.Server.Interfaces
internal interface IBaseServerInternal : IBaseServer
{
bool DisableLoadContext { set; }
void OverrideMainLoop(IGameLoop gameLoop);
void SetCommandLineArgs(CommandLineArgs args);

View File

@@ -20,7 +20,7 @@ namespace Robust.Server
Start(args);
}
internal static void Start(string[] args)
internal static void Start(string[] args, bool contentStart=false)
{
if (_hasStarted)
{
@@ -31,11 +31,11 @@ namespace Robust.Server
if (CommandLineArgs.TryParse(args, out var parsed))
{
ParsedMain(parsed);
ParsedMain(parsed, contentStart);
}
}
private static void ParsedMain(CommandLineArgs args)
private static void ParsedMain(CommandLineArgs args, bool contentStart)
{
IoCManager.InitThread();
ServerIoC.RegisterIoC();
@@ -45,6 +45,10 @@ namespace Robust.Server
var server = IoCManager.Resolve<IBaseServerInternal>();
// When the game is ran with the startup executable being content,
// we have to disable the separate load context.
// Otherwise the content assemblies will be loaded twice which causes *many* fun bugs.
server.DisableLoadContext = contentStart;
server.SetCommandLineArgs(args);
Logger.Info("Server -> Starting");