Closed szotsaki closed 10 months ago
Difficult to track down without debug symbols :/
Questions:
Google isn't really that helpful for that error message. I assumed we're trying to convert a NaN
to int
somewhere, but in a quick test, converting a NaN
to int
results in 0
(not an error). Converting Inf
to int
results in integer overflow
. So... not sure what exactly triggered this.
Edit: correction, converting Inf
to int
in Chrome (as opposed to Firefox) does result in float unrepresentable in integer range
. So does converting e.g. 8589934592.0
(2^33) to int.
There seems to be a -s BINARYEN_TRAP_MODE=clamp
flag for emcc to instead clamp those conversion to the 32 bit int range. But I'd rather like to know the culprit of this error.
I was able to track it down after all. Linking with -g2
was enough to get the function names in the WASM build, without shifting any offsets, so 0x143b1
was still the same code.
The bug was in hud_draw_target_icon()
which draws the reticle when you have the missile or ebolt weapon. The reticle position is projected from world space into screen space, so we can draw it in the hud. If the projected z position is right on the screen plane (i.e. the target is directly right or left of you), the x position can get astronomically high and thus cause this overflow.
The above commit simply checks that 1) the target is in front of you, not behind and 2) the projection position is indeed on the screen. This happens before the conversion to integer pixel coordinates.
Thanks for the report! I learned something today :]
Nice catch and thank you for the quick fix!
Minimal version, 40 seconds into the game, just trying it out. Chromium console shown:
All settings were kind of random in the main menu, so it's possible that I cannot reproduce it. I was pressing
x
continuously andz
multiple times. Hopefully, the screenshot helps a bit more to identify the location:Assembly: