summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-07-03 21:55:31 +1200
committerBen Bridle <ben@derelict.engineering>2025-07-03 21:55:31 +1200
commit667734aa76f9194d4a8627a94c23598303cc7521 (patch)
treefdc9d3606b3ea042bba30ca6b4e257f88371cea5
parentc205d8069270aeb8deda690210b27d3039ea232f (diff)
downloadbedrock-js-667734aa76f9194d4a8627a94c23598303cc7521.zip
Prevent error when stack overflows
Previously, the stack overflowing would cause the stack pointer to point outside of the stack, which would cause an error in the stack printing code.
-rw-r--r--bedrock.js4
1 files changed, 3 insertions, 1 deletions
diff --git a/bedrock.js b/bedrock.js
index 99d2319..1b47b63 100644
--- a/bedrock.js
+++ b/bedrock.js
@@ -405,7 +405,9 @@ function EmulatorElement(options) {
emulator.updateStatePanel = function() {
function renderStack(stack) {
let string = '';
- for (let i=0; i<stack.p; i++) string += hex(stack.mem[i], 2) + ' ';
+ for (let i=0; i<stack.p && i<stack.mem.length; i++) {
+ string += hex(stack.mem[i], 2) + ' ';
+ }
return string;
}
pcState.textContent = hex(br.p, 4);