I’m running into “(Technical trouble: Heap space exhausted. Attempting to recover with UNDO.)” errors in my current work in progress, and I’m struggling to work out what I’ve done wrong.
The errors occur if you use custom verbs or refer to objects that are out of scope.
The errors don’t occur if I’m using the interactive debugger, only if I compile to z5 or z8 and run the file in WinFrotz or Gargoyle.
Looking at this page in the manual, I added (display memory statistics) to the (error $Code entry point) predicate and can see that when things blow up, the last recorded main heap is about half full - regardless of if I increase the heap to maximum in the compiler options, so that all sounds like an infinite loop of some sort.
But I only started encountering this issue after adding a few more objects to the game. And if I delete any random two to four objects, the error goes away.
My game is doing a bunch of stuff that’s a bit strange (messing with undo, moving lots of NPCs around, short-circuiting lots of verbs for particular objects), but I can remove all that behaviour and the error still crops up. But deleting one particular (on every tick) rule seems to stop it.
Except that rule should fail unless the player is in a room with a particular property, and the error crops up in rooms without that property. Deleting the contents of the if/elseif statements in that predicate seem to fix the issue, but why are they eating up infinite memory? Especially when all the conditions to trigger them are false? Why do they stop eating up infinite memory if I delete a couple of unrelated objects?
Can anyone help me work out what I can do to debug this? I’m not sure what code I could post here aside from the entire source code of my work in progress, but here is the (on every tick) rule that seems to be causing the issue. FYI, “current room” is not “adumbral”.
(on every tick)
(current room $Room)
(adumbral $Room)
~(#Countess is nowhere)
~(#Countess is in room $Room)
(#Countess is in room $Here)
(par)
(if)(#Countess is scuttling)(then)
Something scrabbles in the darkness, drawing slowly closer.
(now)~(#Countess is scuttling)
(elseif)($Here = #QuarantineZone)(then)
(if)(#Countess faces #west)(then)
(let #Countess go #west)
(countess crawls)
(else)
(now)(#Countess faces #west)
(countess turns)
(endif)
(elseif)($Here = #CoreBay3)(then)
(if)(#Countess faces #south)(then)
(let #Countess go #south)
(countess crawls)
(else)
(now)(#Countess faces #south)
(countess turns)
(endif)
(elseif) (first step from $Here to $Room is $Dir) (then)
(if)(#Countess faces $Dir)(then)
(let #Countess go $Dir)
(countess crawls)
(else)
(now)(#Countess faces $Dir)
(countess turns)
(endif)
(endif)
Experimenting a bit more, deleting all the (now)(#Countess faces $) lines seems to stop the issue. But why?! How can I debug this?