From 4b4885b65c6d1039d1f7d38aa0c4548a4f14b0a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 6 Jul 2014 22:38:56 +0200 Subject: [PATCH] Fixed computers crashing when mods cause computers to pause (`context.pause(...)`) in a direct callback (`@Callback(direct = true)`). --- .../oc/server/component/machine/Machine.scala | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/scala/li/cil/oc/server/component/machine/Machine.scala b/src/main/scala/li/cil/oc/server/component/machine/Machine.scala index 63b88906a..9c9d4caf5 100644 --- a/src/main/scala/li/cil/oc/server/component/machine/Machine.scala +++ b/src/main/scala/li/cil/oc/server/component/machine/Machine.scala @@ -787,17 +787,27 @@ class Machine(val owner: Owner, constructor: Constructor[_ <: Architecture]) ext switchTo(Machine.State.Stopping) } case result: ExecutionResult.Error => - if (result.message != null) { - crash(result.message) - } - else { - crash("unknown error") - } + crash(Option(result.message).getOrElse("unknown error")) } case Machine.State.Paused => state.pop() // Paused state.pop() // Running, no switchTo to avoid new future. - state.push(Machine.State.Yielded) + result match { + case result: ExecutionResult.Sleep => + remainIdle = result.ticks + state.push(Machine.State.Sleeping) + case result: ExecutionResult.SynchronizedCall => + state.push(Machine.State.SynchronizedCall) + case result: ExecutionResult.Shutdown => + if (result.reboot) { + state.push(Machine.State.Restarting) + } + else { + state.push(Machine.State.Stopping) + } + case result: ExecutionResult.Error => + crash(Option(result.message).getOrElse("unknown error")) + } state.push(Machine.State.Paused) case Machine.State.Stopping => // Nothing to do, we'll die anyway. case _ => throw new AssertionError("Invalid state in executor post-processing.")