Merge pull request #3619 from Snarling/usedRamFix

MISC: FIX #3593 Float errors can no longer prevent full usage of a server's available ram.
This commit is contained in:
hydroflame 2022-05-13 11:06:49 -04:00 committed by GitHub
commit 386dac4be2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 9 deletions

@ -84,7 +84,7 @@ export function NetscriptSingularity(player: IPlayer, workerScript: WorkerScript
if (script.filename === cbScript) { if (script.filename === cbScript) {
const ramUsage = script.ramUsage; const ramUsage = script.ramUsage;
const ramAvailable = home.maxRam - home.ramUsed; const ramAvailable = home.maxRam - home.ramUsed;
if (ramUsage > ramAvailable) { if (ramUsage > ramAvailable + 0.001) {
return; // Not enough RAM return; // Not enough RAM
} }
const runningScriptObj = new RunningScript(script, []); // No args const runningScriptObj = new RunningScript(script, []); // No args

@ -532,7 +532,7 @@ function createAndAddWorkerScript(
const oneRamUsage = getRamUsageFromRunningScript(runningScriptObj); const oneRamUsage = getRamUsageFromRunningScript(runningScriptObj);
const ramUsage = roundToTwo(oneRamUsage * threads); const ramUsage = roundToTwo(oneRamUsage * threads);
const ramAvailable = server.maxRam - server.ramUsed; const ramAvailable = server.maxRam - server.ramUsed;
if (ramUsage > ramAvailable) { if (ramUsage > ramAvailable + 0.001) {
dialogBoxCreate( dialogBoxCreate(
`Not enough RAM to run script ${runningScriptObj.filename} with args ` + `Not enough RAM to run script ${runningScriptObj.filename} with args ` +
`${arrayToString(runningScriptObj.args)}. This likely occurred because you re-loaded ` + `${arrayToString(runningScriptObj.args)}. This likely occurred because you re-loaded ` +
@ -750,7 +750,7 @@ export function runScriptFromScript(
if (server.hasAdminRights == false) { if (server.hasAdminRights == false) {
workerScript.log(caller, () => `You do not have root access on '${server.hostname}'`); workerScript.log(caller, () => `You do not have root access on '${server.hostname}'`);
return 0; return 0;
} else if (ramUsage > ramAvailable) { } else if (ramUsage > ramAvailable + 0.001) {
workerScript.log( workerScript.log(
caller, caller,
() => () =>

@ -63,13 +63,11 @@ export function runScript(
return; return;
} }
if (ramUsage > ramAvailable) { if (ramUsage > ramAvailable + 0.001) {
terminal.error( terminal.error(
"This machine does not have enough RAM to run this script with " + "This machine does not have enough RAM to run this script" +
numThreads + (numThreads === 1 ? "" : ` with ${numThreads} threads`) +
" threads. Script requires " + `. Script requires ${numeralWrapper.formatRAM(ramUsage)} of RAM`,
numeralWrapper.formatRAM(ramUsage) +
" of RAM",
); );
return; return;
} }