mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-31 13:42:59 +00:00 
			
		
		
		
	Shut down computers on errors
Previously we would attempt to resume them, which then caused confusing behaviour if the Lua VM was in an inconsistent state. Closes #811
This commit is contained in:
		| @@ -251,6 +251,20 @@ final class ComputerExecutor | ||||
|      * and then schedule a shutdown. | ||||
|      */ | ||||
|     void abort() | ||||
|     { | ||||
|         immediateFail( StateCommand.ABORT ); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Abort this whole computer due to an internal error. This will immediately destroy the Lua machine, | ||||
|      * and then schedule a shutdown. | ||||
|      */ | ||||
|     void fastFail() | ||||
|     { | ||||
|         immediateFail( StateCommand.ERROR ); | ||||
|     } | ||||
|  | ||||
|     private void immediateFail( StateCommand command ) | ||||
|     { | ||||
|         ILuaMachine machine = this.machine; | ||||
|         if( machine != null ) machine.close(); | ||||
| @@ -258,7 +272,7 @@ final class ComputerExecutor | ||||
|         synchronized( queueLock ) | ||||
|         { | ||||
|             if( closed ) return; | ||||
|             command = StateCommand.ABORT; | ||||
|             this.command = command; | ||||
|             if( isOn ) enqueue(); | ||||
|         } | ||||
|     } | ||||
| @@ -596,6 +610,12 @@ final class ComputerExecutor | ||||
|                     displayFailure( "Error running computer", TimeoutState.ABORT_MESSAGE ); | ||||
|                     shutdown(); | ||||
|                     break; | ||||
|  | ||||
|                 case ERROR: | ||||
|                     if( !isOn ) return; | ||||
|                     displayFailure( "Error running computer", "An internal error occurred, see logs." ); | ||||
|                     shutdown(); | ||||
|                     break; | ||||
|             } | ||||
|         } | ||||
|         else if( event != null ) | ||||
| @@ -644,6 +664,7 @@ final class ComputerExecutor | ||||
|         SHUTDOWN, | ||||
|         REBOOT, | ||||
|         ABORT, | ||||
|         ERROR, | ||||
|     } | ||||
|  | ||||
|     private static final class Event | ||||
|   | ||||
| @@ -506,6 +506,8 @@ public final class ComputerThread | ||||
|                 catch( Exception | LinkageError | VirtualMachineError e ) | ||||
|                 { | ||||
|                     ComputerCraft.log.error( "Error running task on computer #" + executor.getComputer().getID(), e ); | ||||
|                     // Tear down the computer immediately. There's no guarantee it's well behaved from now on. | ||||
|                     executor.fastFail(); | ||||
|                 } | ||||
|                 finally | ||||
|                 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jonathan Coates
					Jonathan Coates