KhymChanur: I've found what looks like a memory trampling bug in flag_remove(), though it might just be tickling a pre-existing hitherto hidden memory bug; the bug comes up after opening a disarmed treasure chest. When flag_remove() is called in traps.do_disarm_object() (line 493 of engine/traps.lua), this causes either FLAG_AMOUNT of the disarmed object to be set to zero (thus making it so that nothing falls out of the chest when it's opened), or causes the invocation of chests.cleanup() in chests.open_large() (line 265 of tome/data/items/items.lua) to give this Lua error:

error: undefined global variable 'chests'
stack traceback:
   1:  function `error' [C]
   2:  function `safe_getglobal' at line 133 [file `/engine/globals.lua']
   3:  function `func' at line 266 [file `/data/items/items.lua']
   4:  method `process_all' at line 30 [file `/engine/hooks.lua']
   5:  function <191:file `/engine/hooks.lua'> at line 195

even though "chests" is clearly a defined global variable. Whether the bug manifests as no objects in the chest or the Lua scripting error varies from one ToME session to the next, but within the same session it's always manifests the same way.

Changing flag_remove(obj.flags, FLAG_TRAP) to flag_remove_zap(obj.flags, FLAG_TRAP) doesn't fix the problem, so I don't think the problem is from flag_remove() freeing the memory of the FLAG_TRAP flagset.

Editing a chest's flagest in tome/data/items/items.lua so that it includes FLY=1 and FEATHER=1 will make the bug go away for that particular kind of chest.

To duplicate the bug:

DevBugReport1 (last edited 2005-06-21 10:22:52 by KhymChanur)