diff --git a/MBBSEmu/HostProcess/ExportedModules/ExportedModuleBase.cs b/MBBSEmu/HostProcess/ExportedModules/ExportedModuleBase.cs index 07ef10cb..4529d7ca 100644 --- a/MBBSEmu/HostProcess/ExportedModules/ExportedModuleBase.cs +++ b/MBBSEmu/HostProcess/ExportedModules/ExportedModuleBase.cs @@ -681,7 +681,11 @@ private protected ReadOnlySpan ProcessTextVariables(ReadOnlySpan out var txtvarsFound = _textVariableService.ExtractVariableDefinitions(outputBuffer); - var txtvarDictionary = ChannelDictionary[ChannelNumber].SessionVariables; + //This can happen if a channel disconnects during the processing of the main loop + if (!ChannelDictionary.TryGetValue(ChannelNumber, out var channelSession)) + return outputBuffer; + + var txtvarDictionary = channelSession.SessionVariables; //Get Their Values var txtvarMemoryBase = Module.Memory.GetVariablePointer("TXTVARS");