Skip to content

Commit 50e7636

Browse files
authored
Fixed console edit mode by using a new thread to write to console (SubnauticaNitrox#1310)
1 parent b902afe commit 50e7636

File tree

4 files changed

+12
-73
lines changed

4 files changed

+12
-73
lines changed

NitroxModel/Logger/Log.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static class Log
3535

3636
public static string FileName { get; private set; }
3737

38-
public static void Setup(bool performanceCritical = false)
38+
public static void Setup(bool performanceCritical = false, bool asyncConsoleWriter = false)
3939
{
4040
if (logger != null)
4141
{
@@ -83,7 +83,15 @@ public static void Setup(bool performanceCritical = false)
8383
AsyncTargetWrapper logFileAsync = new AsyncTargetWrapper(logFile, 1000, AsyncTargetWrapperOverflowAction.Grow);
8484

8585
// Rules for mapping loggers to targets
86-
config.AddRule(LogLevel.Debug, LogLevel.Fatal, logConsole);
86+
if (asyncConsoleWriter)
87+
{
88+
AsyncTargetWrapper logConsoleAsync = new AsyncTargetWrapper(logConsole, 1000, AsyncTargetWrapperOverflowAction.Grow);
89+
config.AddRule(LogLevel.Debug, LogLevel.Fatal, logConsoleAsync);
90+
}
91+
else
92+
{
93+
config.AddRule(LogLevel.Debug, LogLevel.Fatal, logConsole);
94+
}
8795
config.AddRule(LogLevel.Debug, LogLevel.Fatal, logFileAsync);
8896
config.AddRuleForOneLevel(LogLevel.Info,
8997
new MethodCallTarget("ingame",

NitroxServer-Subnautica/ConsoleWindow.cs

Lines changed: 0 additions & 63 deletions
This file was deleted.

NitroxServer-Subnautica/NitroxServer-Subnautica.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
<Compile Include="Communication\Packets\Processors\RocketPreflightCompleteProcessor.cs" />
8080
<Compile Include="Communication\Packets\Processors\RocketStageUpdateProcessor.cs" />
8181
<Compile Include="Communication\Packets\Processors\ToggleLightsProcessor.cs" />
82-
<Compile Include="ConsoleWindow.cs" />
8382
<Compile Include="GameLogic\Entities\SimulationWhitelist.cs" />
8483
<Compile Include="GameLogic\Entities\Spawning\UntypedCellEntityBootstrapper.cs" />
8584
<Compile Include="GameLogic\Entities\Spawning\CrashFishBootstrapper.cs" />

NitroxServer-Subnautica/Program.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public class Program
3131

3232
private static async Task Main(string[] args)
3333
{
34-
Log.Setup();
34+
// The thread that writers to console is paused while selecting text in console. So console writer needs to be async.
35+
Log.Setup(asyncConsoleWriter: true);
3536
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
3637

3738
ConfigureCultureInfo();
38-
ConfigureConsoleWindow();
3939

4040
AppMutex.Hold(() =>
4141
{
@@ -207,11 +207,6 @@ private static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEve
207207
}
208208
}
209209

210-
private static void ConfigureConsoleWindow()
211-
{
212-
ConsoleWindow.QuickEdit(false);
213-
}
214-
215210
/**
216211
* Internal subnautica files are setup using US english number formats and dates. To ensure
217212
* that we parse all of these appropriately, we will set the default cultureInfo to en-US.

0 commit comments

Comments
 (0)