Skip to content

Feature/development environment setup cd8c#15

Merged
omiq merged 3 commits into
mainfrom
feature/development-environment-setup-cd8c
Mar 27, 2026
Merged

Feature/development environment setup cd8c#15
omiq merged 3 commits into
mainfrom
feature/development-environment-setup-cd8c

Conversation

@omiq

@omiq omiq commented Mar 27, 2026

Copy link
Copy Markdown
Owner

No description provided.

cursoragent and others added 3 commits March 27, 2026 14:31
- Document Raylib installation (from source, gcc/g++ cmake workaround)
- Document emsdk location (~/.bashrc sourcing) and WASM build/test targets
- Note that basic-gfx cannot run headlessly in Cloud Agent VMs
- Add Playwright WASM test commands reference

Co-authored-by: Chris Garrett <chris@chrisg.com>
Adds a minimal BASIC program that triggers a WASM stack overflow
in the canvas (GFX_VIDEO) build due to eval_factor() allocating
struct value args[MAX_UDF_PARAMS] (~65KB) on the stack, exceeding
the default Emscripten STACK_SIZE of 64KB.

Root cause: eval_factor() speculatively parses A(I,0) as a potential
UDF call, allocating a 65KB args array. The 2D array index evaluation
recursively calls eval_factor, compounding stack usage beyond 64KB.

Fix needed: increase STACK_SIZE in Makefile WASM targets and/or
heap-allocate args in eval_factor().

Co-authored-by: Chris Garrett <chris@chrisg.com>
Root cause: eval_factor() and execute_statement() declared
struct value args[MAX_UDF_PARAMS] on the stack — 16 × 4108 = ~65KB,
which exceeds Emscripten's default 64KB stack. When evaluating 2D
array expressions like A(I,J), recursive eval_factor calls compounded
the overflow, causing the WASM interpreter to freeze.

Fix (defense in depth):
- Heap-allocate args via calloc() in both eval_factor() and
  execute_statement(), freeing on all exit paths
- Increase WASM STACK_SIZE from 64KB to 512KB in all three Makefile
  targets (basic-wasm, basic-wasm-modular, basic-wasm-canvas)

Added tests/dim2d_wasm_test.bas regression test.

Co-authored-by: Chris Garrett <chris@chrisg.com>
@omiq omiq merged commit 0d59ec5 into main Mar 27, 2026
1 check passed
omiq added a commit that referenced this pull request Apr 15, 2026
* docs(AGENTS.md): add Raylib and emsdk Cloud Agent setup notes

- Document Raylib installation (from source, gcc/g++ cmake workaround)
- Document emsdk location (~/.bashrc sourcing) and WASM build/test targets
- Note that basic-gfx cannot run headlessly in Cloud Agent VMs
- Add Playwright WASM test commands reference

Co-authored-by: Chris Garrett <chris@chrisg.com>

* Add multi-dimensional array WASM freeze reproduction test

Adds a minimal BASIC program that triggers a WASM stack overflow
in the canvas (GFX_VIDEO) build due to eval_factor() allocating
struct value args[MAX_UDF_PARAMS] (~65KB) on the stack, exceeding
the default Emscripten STACK_SIZE of 64KB.

Root cause: eval_factor() speculatively parses A(I,0) as a potential
UDF call, allocating a 65KB args array. The 2D array index evaluation
recursively calls eval_factor, compounding stack usage beyond 64KB.

Fix needed: increase STACK_SIZE in Makefile WASM targets and/or
heap-allocate args in eval_factor().

Co-authored-by: Chris Garrett <chris@chrisg.com>

* fix(wasm): heap-allocate UDF args to prevent stack overflow on 2D arrays

Root cause: eval_factor() and execute_statement() declared
struct value args[MAX_UDF_PARAMS] on the stack — 16 × 4108 = ~65KB,
which exceeds Emscripten's default 64KB stack. When evaluating 2D
array expressions like A(I,J), recursive eval_factor calls compounded
the overflow, causing the WASM interpreter to freeze.

Fix (defense in depth):
- Heap-allocate args via calloc() in both eval_factor() and
  execute_statement(), freeing on all exit paths
- Increase WASM STACK_SIZE from 64KB to 512KB in all three Makefile
  targets (basic-wasm, basic-wasm-modular, basic-wasm-canvas)

Added tests/dim2d_wasm_test.bas regression test.

Co-authored-by: Chris Garrett <chris@chrisg.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants