How do I debug memory stack run-time errors?

I’m getting the following:

> **go to lees trailer**

[** Programming error: tried to write to -->160 in the array "MStack", which has entries 0 up to 159 **]

*** Run-time problem P46: The memory stack is exhausted.

Mstack backtrace: size 159 words
Block at 152 owner ID 11 size 6
1 0 540 541 542 1

and on for about 2 pages. There is no clue what I’m doing to cause this. Is this one of those “increase some limit” things or rather a likely error in my code?

I’ve never encountered this, but just based on my experience with programming in general it sounds like a stack overflow caused by an infinite loop of some sort. It would probably help if you posted the relevant rules that are likely to fire in this context (or just all your code if you don’t know).

It’s most commonly caused by "try"ing an action within the same action (“Instead of going to Lee’s trailer, try going to Lee’s trailer”) or bouncing between multiple actions (“Instead of jumping, try waiting. Instead of waiting, try jumping.”) Of course the actual code is usually more complex but that’s the gist of it.

You can find what rule is causing it by turning on rules tracking by commanding RULES before doing the command that crashes it. It should show a long repeating list of rules, the last rule before it starts repeating is the one that ultimately causes the infinite loop.

3 Likes

Great, that helped. I forgot that testing command existed.

It was a simple navigation rule I had added forever ago to allow the player to exit an indoor location easily.

Instead of exiting when player is in Room_Lees_Trailer:
    Try room_navigating to Room_C_loop;

But then I added a new direction relationship to help navigation:

Outside from Room_Lees_Trailer is Room_C_loop.

…forgetting that room_navigating involves going to a heading (in this case outside). So every time the player tried to exit it ran the instead rule, triggering the instead rule, etc.

Nixing the instead rule solved it.