Closed hugoam closed 6 years ago
Thanks for the report. Will take a look probably tomorrow. Yes, padding all commands to some predefined alignment should be the way to go.
I just pushed some changes regarding this bug.
The only way I could reproduce the crash was with -s SAFE_HEAP=1. Without it, WebAssembly (-s WASM=1) worked without a problem (as it's supposed to since it supports unaligned accesses), and asm.js (i.e. no WASM flag) asserted here https://github.com/jdryg/vg-renderer/blob/master/src/vg.cpp#L4368 But none of them crashed as they do with SAFE_HEAP=1.
Either way, please test it and report back as soon as you find the time.
@hugoam Any news on this one? Does it still happen with the latest version of the code?
Hey ! I might have confused WASM and asmjs when reporting the issue, it might have happened in the asmjs build. But it doesn't happen anymore in either of my builds, so I think your solution is perfect :)
I took half a day to track down a nasty error that happened only when compiling to Emscripten + WebAssembly.
Apparently the problem is an alignment issue : in WebAssembly it seems you can't have commands aligned on 2 bytes, and it happens that the
CreateImagePattern
is the only one that has a total size that is not a multiple of 4. (it's 30 bytes large)As a result, in WebAssembly, any call to
CreateImagePattern
completely messes up the rest of the command list.Here is a raw git diff of a workaround to fix that, which is padding the command with another uint16_t. This is not a really nice solution, it's just a quick fix, so I suppose you can think of a nicer one (like forcing all commands to be padded to a multiple of 4 ?)