-
Notifications
You must be signed in to change notification settings - Fork 241
Description
I've had several reports of the same error, but haven't seen it myself, where upon loading the scene, this starts spamming the log:
[EXC 10:55:51.196] ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <ad04dee02e7e4a85a1299c7ee81c79f6>:0)
System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <ad04dee02e7e4a85a1299c7ee81c79f6>:0)
kOS.Screen.Interpreter.IsWaitingForCommand () (at <3ccb18ebae2a49929054690a1a176760>:0)
kOS.Screen.TermWindow.ProcessUnconsumedInput () (at <3ccb18ebae2a49929054690a1a176760>:0)
kOS.Screen.TermWindow.Update () (at <3ccb18ebae2a49929054690a1a176760>:0)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
ModuleManager.UnityLogHandle.InterceptLogHandler:LogException(Exception, Object)
UnityEngine.Debug:CallOverridenDebugHandler(Exception, Object)
[EXC 10:55:51.349] ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <ad04dee02e7e4a85a1299c7ee81c79f6>:0)
System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <ad04dee02e7e4a85a1299c7ee81c79f6>:0)
kOS.Screen.Interpreter.IsWaitingForCommand () (at <3ccb18ebae2a49929054690a1a176760>:0)
kOS.Screen.TermWindow.ProcessUnconsumedInput () (at <3ccb18ebae2a49929054690a1a176760>:0)
kOS.Screen.TermWindow.Update () (at <3ccb18ebae2a49929054690a1a176760>:0)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
ModuleManager.UnityLogHandle.InterceptLogHandler:LogException(Exception, Object)
UnityEngine.Debug:CallOverridenDebugHandler(Exception, Object)
[EXC 10:55:51.500] ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <ad04dee02e7e4a85a1299c7ee81c79f6>:0)
System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <ad04dee02e7e4a85a1299c7ee81c79f6>:0)
kOS.Screen.Interpreter.IsWaitingForCommand () (at <3ccb18ebae2a49929054690a1a176760>:0)
kOS.Screen.TermWindow.ProcessUnconsumedInput () (at <3ccb18ebae2a49929054690a1a176760>:0)
kOS.Screen.TermWindow.Update () (at <3ccb18ebae2a49929054690a1a176760>:0)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
ModuleManager.UnityLogHandle.InterceptLogHandler:LogException(Exception, Object)
UnityEngine.Debug:CallOverridenDebugHandler(Exception, Object)
It might be possible to trigger it using a boot file that tries to read terminal input keys right away.
Looking at the code, I believe the cause of this is a race condition between the work done by kOS during the Unity Update versus the work done by kOS during the Unity FixedUpdate. In order for the problem to happen, kOS has to run its Update before it runs its first FixedUpdate for the newly loaded scene.
The FixedUpdate runs the Cpu.Boot() method on the first FixedUpdate pass. This initializes the Interpreter's context.Program with its starting dummy program of one OpcodeEOF.
But the Update (not FixedUpdate) runs ProcessUnconsumedInput() for the terminal, which in turn calls Interpreter.IsWaitingForCommand(), which tries to access context.Program's first opcode, that hasn't been initialized yet if the FixedUpdate hasn't happened and thus the Boot() hasn't happened.
I think the fix should involve making sure that ProcessUnconsumedInput() doesn't do anything until after the boot has finished.