Skip to content

Say that termcade_init has to come first - #14

Merged
nicodes merged 1 commit into
mainfrom
abi-call-order
Aug 3, 2026
Merged

Say that termcade_init has to come first#14
nicodes merged 1 commit into
mainfrom
abi-call-order

Conversation

@nicodes

@nicodes nicodes commented Aug 3, 2026

Copy link
Copy Markdown
Member

The ABI lists the exports without stating that one of them constructs the game. Read the table and you would reasonably call termcade_playfield first to learn how big a framebuffer to allocate — and take a nil pointer dereference inside the guest.

abi           1
panic: runtime error: invalid memory address or nil pointer dereference
	tcgame.termcadePlayfield()
	sdk/tcgame/export.go:66

The arcade has always had the order right (termcade_abitermcade_inittermcade_playfield, internal/plugin/wasmgame.go:40-58), which is precisely why nothing caught it: the only host was the one that already knew.

How it surfaced

Running tetris.tcade under a JS WebAssembly engine with a WASI preview-1 shim, to find out whether the Expo app could host games rather than only list them. Once the order was fixed, the same package ran 90 frames and rasterised correctly:

abi           1
playfield     32x40
framebuffer   64x40 = 10240 bytes (matches ABI)
status        running
lit pixels    136 / 2560 (5.3%)
distinct RGB  5
hud           {"Fields":[{"Label":"SCORE","Value":"000000","Accent":true},…

That is a docs-only change here; the renderer work is separate.

🤖 Generated with Claude Code

The ABI lists the exports without stating that one of them constructs
the game, so a second host implementation reads the table, calls
termcade_playfield to learn the framebuffer size, and takes a nil
pointer dereference inside the guest.

Found by running tetris under a JS WebAssembly engine to see whether the
app could host games too. The arcade has always had the order right —
abi, init, playfield — which is exactly why nothing caught it: the only
host was the one that already knew.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@nicodes
nicodes merged commit f7e7c71 into main Aug 3, 2026
1 check passed
@nicodes
nicodes deleted the abi-call-order branch August 3, 2026 09:04
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.

1 participant