From 8fafec491593ede24e631c6a33d0f4bc3c80a1b1 Mon Sep 17 00:00:00 2001 From: SquidDev Date: Wed, 1 May 2019 15:26:55 +0100 Subject: [PATCH] Fix budget growing too much We were using += instead of =, meaning the budget always grew, rather than growing while there was still space. As a result, computers were never correctly rate limited. Further more, if a computer went into a deficit, we would continue to increase the budget by a negative amount, exponentially decreasing until overflowing! Yes, this is a very embarrassing mistake. I'd been aware that rate limiting wasn't working as expected for a while, I hadn't realised the problem would be this stupid. --- .../java/dan200/computercraft/core/computer/MainThread.java | 2 +- .../dan200/computercraft/core/computer/MainThreadExecutor.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/dan200/computercraft/core/computer/MainThread.java b/src/main/java/dan200/computercraft/core/computer/MainThread.java index 70be93c1d..9bddaee4e 100644 --- a/src/main/java/dan200/computercraft/core/computer/MainThread.java +++ b/src/main/java/dan200/computercraft/core/computer/MainThread.java @@ -134,7 +134,7 @@ public final class MainThread // Of course, we'll go over the MAX_TICK_TIME most of the time, but eventually that overrun will accumulate // and we'll skip a whole tick - bringing the average back down again. currentTick++; - budget += Math.min( budget + ComputerCraft.maxMainGlobalTime, ComputerCraft.maxMainGlobalTime ); + budget = Math.min( budget + ComputerCraft.maxMainGlobalTime, ComputerCraft.maxMainGlobalTime ); canExecute = budget > 0; // Cool down any warm computers. diff --git a/src/main/java/dan200/computercraft/core/computer/MainThreadExecutor.java b/src/main/java/dan200/computercraft/core/computer/MainThreadExecutor.java index 8d12d6dbd..955b48c65 100644 --- a/src/main/java/dan200/computercraft/core/computer/MainThreadExecutor.java +++ b/src/main/java/dan200/computercraft/core/computer/MainThreadExecutor.java @@ -224,7 +224,7 @@ final class MainThreadExecutor implements IWorkMonitor { state = State.COOLING; currentTick = MainThread.currentTick(); - budget += Math.min( budget + ComputerCraft.maxMainComputerTime, ComputerCraft.maxMainComputerTime ); + budget = Math.min( budget + ComputerCraft.maxMainComputerTime, ComputerCraft.maxMainComputerTime ); if( budget < ComputerCraft.maxMainComputerTime ) return false; state = State.COOL;