From 05bab2280754f59bb32b013ec31c9e6e3e24eaab Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Sat, 4 Sep 2021 19:27:16 -0400 Subject: [PATCH] Better error message for dynamic ram miscalculation --- src/NetscriptFunctions.js | 30 +++++++++++++++++++++--------- src/ThirdParty/raphael.min.js | 18 ++++++++---------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index 0f291769d..cad5fe393 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -243,15 +243,27 @@ function NetscriptFunctions(workerScript) { if (workerScript.dynamicRamUsage > 1.01 * workerScript.ramUsage) { throw makeRuntimeRejectMsg( workerScript, - "Dynamic RAM usage calculated to be greater than initial RAM usage on fn: " + - fnName + - ". This is probably because you somehow circumvented the static RAM " + - "calculation.

Please don't do that :(

" + - "Dynamic RAM Usage: " + - numeralWrapper.formatRAM(workerScript.dynamicRamUsage) + - "
" + - "Static RAM Usage: " + - numeralWrapper.formatRAM(workerScript.ramUsage), + `Dynamic RAM usage calculated to be greater than initial RAM usage on fn: ${fnName}. + This is probably because you somehow circumvented the static RAM calculation. + + Dynamic RAM Usage: ${numeralWrapper.formatRAM( + workerScript.dynamicRamUsage, + )} + Static RAM Usage: ${numeralWrapper.formatRAM(workerScript.ramUsage)} + + One of these could be the reason: + * Using eval() to get a reference to a ns function +   const scan = eval('ns.scan'); + + * Using map access to do the same +   const scan = ns['scan']; + + * Saving script in the improper order. +   Increase the cost of an imported script, save it, then run the +   parent. To fix this just re-open & save every script in order +   from most imported to least imported (parent script). + + Sorry :(`, ); } }; diff --git a/src/ThirdParty/raphael.min.js b/src/ThirdParty/raphael.min.js index 24da42aa5..eb77af8c4 100644 --- a/src/ThirdParty/raphael.min.js +++ b/src/ThirdParty/raphael.min.js @@ -2512,16 +2512,14 @@ a = this.matrix ? Q(a, this.matrix) : a; for (var s = 1; s < r + 1; s++) n.push( - i - .path(a) - .attr({ - stroke: e.color, - fill: e.fill ? e.color : "none", - "stroke-linejoin": "round", - "stroke-linecap": "round", - "stroke-width": +((e.width / r) * s).toFixed(3), - opacity: +(e.opacity / r).toFixed(3), - }), + i.path(a).attr({ + stroke: e.color, + fill: e.fill ? e.color : "none", + "stroke-linejoin": "round", + "stroke-linecap": "round", + "stroke-width": +((e.width / r) * s).toFixed(3), + opacity: +(e.opacity / r).toFixed(3), + }), ); return n.insertBefore(this).translate(e.offsetx, e.offsety); });