NickMcConnell / NarSil

Unofficial rewrite of Sil 1.3.0
13 stars 2 forks source link

Main branch: "Error in flag_on" message when identifying by use #757

Closed backwardsEric closed 29 minutes ago

backwardsEric commented 18 hours ago

In the main branch with https://github.com/NickMcConnell/NarSil/pull/756 applied (compiled from source on macOS with 'make -f Makefile.osx OPT="-O0 -g -DUSE_STATS -fsanitize=address -fsanitize=undefined"), I tried to work through the tutorial. After equipping the special short sword and using it on the orc soldier in the next room, the game exited on the message, "Error in flag_on(lore->flags, flag): FlagID[0] Size[10] FlagOff[4294967295] FlagBV[128]". After setting a breakpoint at the entry to quit() in the debugger and rerunning, the back trace at the point of the error message is:

  1. quit(str="Error in flag_on(lore->flags, flag): FlagID[0] Size[10] FlagOff[4294967295] FlagBV[128]\n") at z-util.c:893
  2. quit_fmt(fmt="Error in flag_on(%s, %s): FlagID[%d] Size[%u] FlagOff[%u] FlagBV[%d]\n") at z-form.c:701
  3. flag_on_dbg(flags="?\U00000002", size=10, flag=0, fi="lore->flags", fl="flag") at z-bitflag.c:220
  4. lore_learn_flag_if_visible(lore=0x0000626000045380, mon=0x000000010e5b0700, flag=0) at mon-lore.c:56
  5. learn_brand_slay_helper(p=0x000061a000014a80, obj1=0x00006100000a3540, obj2=0x0000000000000000, mon=0x000000010e5b0700) at obj-slays.c:306
  6. learn_brand_slay_from_melee(p=0x000061a000014a80, weapon=0x00006100000a3540, mon=0x000000010e5b0700) at obj-slays.c:368
  7. py_attack_real(p=0x000061a000014a80, grid=(x = 41, y = 19), attack_type=0) at player-attack.c:561
  8. py_attack(p=0x000061a000014a80, grid=(x = 41, y = 19), attack_type=0) at player-attack.c:693
  9. move_player(dir=4, disarm=true) at cmd-cave.c:1668
  10. do_cmd_walk(cmd=0x0000000100c63ef0) at cmd-cave.c:2028
  11. process_command(ctx=CTX_GAME, cmd=0x0000000100c63ef0) at cmd-core.c:347
  12. cmdq_pop(c=CTX_GAME) at cmd-core.c:379
  13. process_player at game-world.c:892
  14. run_game_loop at game-world.c:996
  15. play_game(mode=GAME_TUTORIAL) at ui-game.c:932
NickMcConnell commented 14 hours ago

I haven't checked at all, but did have a similar error which was fixed in d17202062

backwardsEric commented 7 hours ago

This looks like it is specific to learning brands or slays (the special short sword is of Gondolin). The logic in Vanilla looks like it's wrong (and was wrong before your simplification three months ago). For brands, I suspect Vanilla should be using

if (!learn && !(allow_temp && player_has_temporary_brand(p, i))) {
    continue;
}

which would simplify to "if (!learn) continue;" in NarSil with some other simplifications in the remainder of the loop since learn will always be true at that point.