From 7db8f7c6a52502e0ad5530bce59e72a87258aaca Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Wed, 17 Apr 2024 23:42:37 +0300 Subject: [PATCH] Fix mention_map and hiders causing a light source error Prevent glyph change messages while loading a level file. Otherwise a monster hiding under an item triggered a vision recalc before light sources were linked to their sources, leading into strange errors looking like pointer corruption. getlev -> hide_monst -> hideunder -> newsym -> show_glyph -> pline_xy -> vision_recalc -> do_light_sources -> get_obj_location Add in_getlev program state variable, analogous to in_mklev --- include/hack.h | 1 + src/display.c | 1 + src/restore.c | 3 +++ src/vision.c | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/hack.h b/include/hack.h index d0c9e7ae1..390be76df 100644 --- a/include/hack.h +++ b/include/hack.h @@ -766,6 +766,7 @@ struct sinfo { int exiting; /* an exit handler is executing */ int saving; /* creating a save file */ int restoring; /* reloading a save file */ + int in_getlev; /* in getlev() */ int in_moveloop; /* normal gameplay in progress */ int in_impossible; /* reporting a warning */ int in_docrt; /* in docrt(): redrawing the whole screen */ diff --git a/src/display.c b/src/display.c index f22bbcb24..16f92f19a 100644 --- a/src/display.c +++ b/src/display.c @@ -1950,6 +1950,7 @@ show_glyph(coordxy x, coordxy y, int glyph) if (a11y.glyph_updates && !a11y.mon_notices_blocked && !gp.program_state.in_docrt + && !gp.program_state.in_getlev && (oldglyph != glyph || gg.gbuf[y][x].gnew)) { int c = glyph_to_cmap(glyph); if ((glyph_is_nothing(oldglyph) || glyph_is_unexplored(oldglyph) diff --git a/src/restore.c b/src/restore.c index c4e136c98..7ff379117 100644 --- a/src/restore.c +++ b/src/restore.c @@ -1005,6 +1005,8 @@ getlev(NHFILE *nhfp, int pid, xint8 lev) short tlev; #endif + gp.program_state.in_getlev = TRUE; + if (ghostly) clear_id_mapping(); @@ -1233,6 +1235,7 @@ getlev(NHFILE *nhfp, int pid, xint8 lev) if (ghostly) clear_id_mapping(); + gp.program_state.in_getlev = FALSE; } void diff --git a/src/vision.c b/src/vision.c index b7caaba2b..997a88715 100644 --- a/src/vision.c +++ b/src/vision.c @@ -521,7 +521,7 @@ vision_recalc(int control) int oldseenv; /* previous seenv value */ gv.vision_full_recalc = 0; /* reset flag */ - if (gi.in_mklev || !iflags.vision_inited) + if (gi.in_mklev || gp.program_state.in_getlev || !iflags.vision_inited) return; /*