I've been playing with wasm4 platform but ran into out of bounds error
here's an ugly prototype of a maze game. level 3 crashes. if to have a bigger field, let's say 20x20 (currently it's 6x6), the game crashes trying to build even the first level.
I thought it was something with recursion/stack overflow during random traversal. but it should be a pretty straightforward TCO case. also, there are no problems for the roc-cli
platform, so it’s probably specific to the allocation mechanism of the wasm4 platform
https://gist.github.com/wontem/50bc86494a59fd7d7fffacc5dabb6e5d
error log
looks like it may be a bug with the allocator...not fully sure yet
The error currently doesn't make sense to me. Looks to be failing an assert in zig but we have a conditional right before the assert that should make it impossible. Not yet sure what is going on. Will have to debug more later.
Skimmed the allocator. Never read allocators or zig and must say, the code is very simple to follow! From what I see, it’s really hardly possible the problem happens because of the allocation for roc.
Looks more like it fails trying to allocate memory on the stack for zig, it just happens to fail during isSet
. Will check it later today. Or maybe the trace log is not accurate
Yeah, I decreased mem_size
and increased stack_size
by 10000
and it helped. Now, the question is why the stack overflow is happening. Seems to be a lack of TCO then. How can I check it? Going to check llvm ir, maybe there is a hint.
Interesting. That makes sense for the random failure location.
could be hitting this compiler bug: https://github.com/roc-lang/roc/issues/6213
We need to cleanup our ir and ensure all stack allocas happen outside of looping code. Otherwise, as the loops run, it can still accumulate stack space.
I used Task.loop
as a workaround. Works well enough
Glad you found a workaround
Last updated: Jul 06 2025 at 12:14 UTC