So, the proximate cause of the failure is from Hypo_Capture_End:
glk_stream_close(glk_stream_get_current(), gg_arguments);
hypo_capture_len = gg_arguments-->1;
glk_stream_set_current(hypo_capture_previous);
hypo_capture_previous = 0;
This closes the current stream, and switches printing back to the stream saved in hypo_capture_previous. This is supposed to only be called after Hypo_Capture_Start saves the current stream in hypo_capture_previous, then creates a new memory stream writing to the hypo_capture array.
Except, for some reason, Hypo_Capture_End is getting called when that’s not the case. So it tries to close the stream that’s printing to the main window, and that crashes and burns.
Oh, wait. I think I see it. It’s from that semicolon I had you insert!
{-my:1} = Hypo_Start({phrase options});
if ({-my:1} == 1) {ph}
Hypo_Middle({R});
if ({-my:1} == 2) Hypo_End();
The intended flow for this code is:
- Set my:1 to Hypo_Start
- If my:1 is 1, then we’re in the hypothetical: call ph, then call Hypo_Middle
- Otherwise, if my:1 is 2, then we’re out of the hypothetical: call Hypo_End
- (Otherwise, if my:1 is 0, then something went wrong. Maybe the interpreter doesn’t support undo. In this case, Hypo_Start should have printed an error message already.)
But inserting that semicolon made it so that Hypo_Middle is called regardless of the state of my:1, meaning it’s called again after the hypothetical ends, when we’re back in the real world.
I believe it should look like this:
{-my:1} = Hypo_Start({phrase options});
if ({-my:1} == 1){
{ph};
Hypo_Middle({R});
} else if ({-my:1} == 2){
Hypo_End();
}
Try that change and see if it works. Later I can fire up Inform and see if this makes one of the examples run properly.
EDIT: The older version, which you can find commented-out in the extension, uses a switch statement, which would make this structure simpler. Since it’s commented out I figure there’s some weird drawback which is why I’m not using that here. But that’s probably better style.
Both the newer code and the older code also pass “phrase options” to Hypo_Start, but no phrase options are defined, either in the phrase or in Hypo_Start. I wonder what that was meant to do.