erkyrath / quixe

A Glulx VM interpreter written in Javascript
http://eblong.com/zarf/glulx/
MIT License
169 stars 33 forks source link

Possible compile_string() bug #49

Open erkyrath opened 2 years ago

erkyrath commented 2 years ago

Described in thread: https://intfiction.org/t/help-fixing-everybody-dies-so-its-playable-online/51346

When iosys is zero, printing a string should silently do nothing. Instead it maybe generates a Glk "stream not set" error?

A couple of places seem to generate glk_put_jstring() calls without checking iosys:

oputil_flush_string() stream_string() accel_func_map error cases

erkyrath commented 2 years ago

Now I'm thinking that it's not compile_string() after all. Looks like msww was correct in the thread that stream_string() should check iosys.

erkyrath commented 2 years ago

The problem turned out to be more subtle than either of us... I think it's fixed now.

accel_func_map errors now only print if iosys is 2. (I have made the same change in glulxe.)

In oputil_flush_string() and stream_string(), we don't need to check iosys. We're printing text buffered for the Glk stream. But we do need to check if the buffered text is empty. The compile_string() layer returns "" if nothing was printed to Glk at all, and we need to not crash in that case.