scratchfoundation / scratch-vm

Virtual Machine used to represent, run, and maintain the state of programs for Scratch 3.0

Home Page:http://scratchfoundation.github.io/scratch-vm/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[ENA-266] JS TypeError when clicking a procedure in the toolbox

alexcui03 opened this issue · comments

Expected Behavior

No Error

Actual Behavior

Uncaught TypeError: Cannot read properties of undefined (reading 'opcode')

Steps to Reproduce

  1. create a procedure as the following picture:
    image
  2. run it by clicking the procedure block in the toolbox, we will get the error in console:
    image

Other Infomation

It causes endless loop in development mode.

Related code src/engine/thread.js:

isRecursiveCall (procedureCode) {
    let callCount = 5; // Max number of enclosing procedure calls to examine.
    const sp = this.stack.length - 1;
    for (let i = sp - 1; i >= 0; i--) {
        const block = this.target.blocks.getBlock(this.stack[i]);
        if (block.opcode === 'procedures_call' &&
            block.mutation.proccode === procedureCode) {
            return true;
        }
        if (--callCount < 0) return false;
    }
    return false;
}

Possible reason: the procedure block from toolbox cannot be get with this.target.blocks.getBlock, so it get undefined. Accessing block.opcode (block is undefined) cause the error.

System Details

Windows 11
Chrome 109.0.5414.122