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 ); }