From 19aca001d721dffc62b49b47739477d72c0955a5 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Wed, 29 May 2019 09:03:31 +0100 Subject: [PATCH] A couple of stability improvements to ComputerThread - Be more generous in what errors we catch, handling some of the more "recoverable" ones. - Should a runner crash, attempt to restart it. --- .../core/computer/ComputerThread.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/dan200/computercraft/core/computer/ComputerThread.java b/src/main/java/dan200/computercraft/core/computer/ComputerThread.java index 518553fe0..f1120e891 100644 --- a/src/main/java/dan200/computercraft/core/computer/ComputerThread.java +++ b/src/main/java/dan200/computercraft/core/computer/ComputerThread.java @@ -133,7 +133,6 @@ static void start() synchronized( threadLock ) { running = true; - if( monitor == null || !monitor.isAlive() ) (monitor = monitorFactory.newThread( new Monitor() )).start(); if( runners == null ) { @@ -158,6 +157,8 @@ static void start() runnerFactory.newThread( runners[i] = new TaskRunner() ).start(); } } + + if( monitor == null || !monitor.isAlive() ) (monitor = monitorFactory.newThread( new Monitor() )).start(); } } @@ -368,7 +369,16 @@ public void run() { TaskRunner runner = currentRunners[i]; // If we've no runner, skip. - if( runner == null ) continue; + if( runner == null || runner.owner == null || !runner.owner.isAlive() ) + { + if( !running ) continue; + + // Mark the old runner as dead and start a new one. + ComputerCraft.log.warn( "Previous runner ({}) has crashed, restarting!", + runner != null && runner.owner != null ? runner.owner.getName() : runner ); + if( runner != null ) runner.running = false; + runnerFactory.newThread( runners[i] = new TaskRunner() ).start(); + } // If the runner has no work, skip ComputerExecutor executor = runner.currentExecutor.get(); @@ -492,7 +502,7 @@ public void run() { executor.work(); } - catch( Exception e ) + catch( Exception | LinkageError | VirtualMachineError e ) { ComputerCraft.log.error( "Error running task on computer #" + executor.getComputer().getID(), e ); }