"undo" after replay input crashes Glulx interpreter
Reported at http://inform7.com/mantis/view.php?id=2046 and https://www.intfiction.org/forum/viewtopic.php?f=7&t=25197&p=138447 by turthalion
Compiled using Inform v6.33 Library v6.12.1 S).
After I replay a command script, even one of only one command, issuing "undo" causes Git and Glulxe report: Reference to non-existent Glk object
Lectrote is, as expected more helpful, showing: Quixe run: glk_get_line_stream: invalid stream
If, without replaying, I take the same command, I can type it in, hit and then type 'undo' and nothing untoward happens.
I've got a minimal example (attached) that demonstrates this.
If it is compiled with -~D in any way, then it crashes when you type undo after inputting a replay file.
in parserm.h in GGRecoverObjects (line 6491 in mine), there's the following:
#Ifdef DEBUG; gg_commandstr = 0; gg_command_reading = false; #Endif; ! DEBUG and a bit further down inside the switch sstatement (line 6503): #Ifdef DEBUG; GG_COMMANDWSTR_ROCK: gg_commandstr = id; gg_command_reading = false; GG_COMMANDRSTR_ROCK: gg_commandstr = id; gg_command_reading = true; #Endif; ! DEBUG
So we only wipe gg_commandstr and clear gg_command_reading when it's a debug build (which, unsurprisingly, is when it works properly for me, not crashing). If it's a release build, gg_commandstr is not cleared.
During discussion at intfiction.org (thread: https://www.intfiction.org/forum/viewtopic.php?f=7&t=25197&p=138447 [^]), zarf had the following to say: "I don't know why the gg_commandstr lines in GGRecoverObjects() are conditionalized with "#ifdef DEBUG". There's no good reason for that, except maybe the expectation that the RECORD command will only be used on debug builds, which is not a good assumption. You can just remove the "#ifdef" lines there."
So I thought I'd post this here and see if anyone knows of a reason those #Ifdefs are there. I can verify that removing both sets seems to address my issue.