Fix NullReferenceException in StartConsoleSession when running with BasicIO

In headless/BasicIO mode, ConsoleIO.Backend remains null because
ClassicConsoleBackend is never initialized. StartConsoleSession()
must guard against a null backend to avoid crashing right after
a successful server join.

Without this fix, BasicIO mode (used for unattended / batch
automation with CREATE_NO_WINDOW) crashes with:

  NullReferenceException: Object reference not set to an instance of an object.
  at MinecraftClient.McClient.StartConsoleSession()

The fix adds an early return when ConsoleIO.Backend is null,
which is safe because BasicIO mode does not need interactive
console input handling at all.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
NicoleDyson 2026-05-18 21:27:52 +08:00
parent b13511f201
commit 1bc57399c8

View file

@ -525,6 +525,9 @@ namespace MinecraftClient
private void StartConsoleSession()
{
if (ConsoleIO.Backend is null)
return;
cmdprompt = new CancellationTokenSource();
if (!consoleReadThreadOwned)