Skip to content

Fix travel moving player back and forth infinitely - #5

Closed
tung wants to merge 1 commit into
NetHack:NetHack-3.6.0from
tung:infinite-travel-fix
Closed

tung wants to merge 1 commit into
NetHack:NetHack-3.6.0from
tung:infinite-travel-fix

Conversation

@tung

@tung tung commented Mar 11, 2016

Copy link
Copy Markdown
Contributor

This fixes a bug where hundreds of turns are wasted by the travel system moving the player back and forth when the player targets an unreachable space and sight-blocking obstacles occur in certain formations in-between. The player will only be stopped if they're interrupted externally, e.g. growing hungry or being hit by a monster. See the comment in the code for full details.

Based on DynaHack commit 02da53e (Fix travel moving player back and forth repeatedly) by me.

This fixes a bug where hundreds of turns are wasted by the travel system
moving the player back and forth when the player targets an unreachable
space and sight-blocking obstacles occur in certain formations
in-between.  The player will only be stopped if they're interrupted
externally, e.g. growing hungry or being hit by a monster.  See the
comment in the code for full details.

Based on DynaHack commit 02da53e (Fix travel moving player back and
forth repeatedly) by me.
@davecohrs

Copy link
Copy Markdown
Contributor

This seems like one of the attempts I tried to fix this bug a few years ago, but found it did not address all situations. There was one in particular, where travel got stuck between 2 traps. Unfortunately, I no longer have that thread or I would forward it.

@paxed paxed closed this May 28, 2016
nhcopier pushed a commit that referenced this pull request Dec 31, 2020
Add a missing opening quote mark near the end of passage 5 of
Lords and Ladies.
nhcopier pushed a commit that referenced this pull request Dec 1, 2022
If you were on a level teleporter, the spoteffects() call after
the hero gets expelled could end up going to a new level and
freeing all the monst chains from the level you were originally
engulfed on.

    #0 0xba0507 in free
    #1 0x87feda in dealloc_monst src/mon.c:2369
    #2 0x880a02 in dmonsfree src/mon.c:2194
    #3 0x9a7aa2 in savelev_core src/save.c:507
    #4 0x9a7a21 in savelev src/save.c:466
    #5 0x71eb9d in goto_level src/do.c:1483
    #6 0x71833f in deferred_goto src/do.c:1903
    #7 0xa2533f in level_tele src/teleport.c:1117
    #8 0xa2567b in level_tele_trap src/teleport.c:1198
    #9 0xa5c007 in trapeffect_level_telep src/trap.c:1861
    #10 0xa5f856 in trapeffect_selector src/trap.c:2497
    #11 0xa47497 in dotrap src/trap.c:2586
    #12 0x7d669b in spoteffects src/hack.c:2859
    #13 0x89d495 in xkilled src/mon.c:3187

The latter parts of xkilled() after the spoteffects() call would
then attempt to dereference the free'd monst pointer.

Save a copy of the monst struct prior to spoteffects() if you were
expelled, then point at the reference copy afterwards.

Resolves #938
nhcopier pushed a commit that referenced this pull request Aug 28, 2023
On GitHub issue 1090, Rhialto wrote:
Hi! I am currently in the process of adapting the pkgsrc packaging of NetHack 3.6.7 to include the curses window option. A bit late perhaps...

While working on that, I ran into a case of a NULL pointer being used. Apparently when linking with ncurses, this doesn't cause problems, but NetBSD's own curses doesn't like it, and crashes the game.

Here is the stack trace. It happens when #quitting, I think just before the high scores are about to be shown (but I guess it should show in the stack trace if I'm totally correct with that):

(gdb) bt
 #0  redrawwin (win=0x0) at /usr/src/lib/libcurses/touchwin.c:149
 #1  0x0000000017e104b4 in curses_refresh_nethack_windows () at ../win/curses/curswins.c:176
 #2  0x0000000017e1054a in curses_destroy_win (win=win@entry=0x7ad219520540) at ../win/curses/curswins.c:155
 #3  0x0000000017e1512c in curses_display_nhmenu (wid=<optimized out>, how=<optimized out>, _selected=0x7f7fff65d850) at ../win/curses/cursdial.c:771
 #4  0x0000000017e0ff81 in curses_select_menu (wid=wid@entry=21, how=how@entry=0, selected=selected@entry=0x7f7fff65d850) at ../win/curses/cursmain.c:607
 #5  0x0000000017e10257 in curses_display_nhwindow (wid=21, block=1) at ../win/curses/cursmain.c:385
 #6  0x0000000017ca8075 in really_done (how=<optimized out>, how@entry=13) at end.c:1609
 #7  0x0000000017ca993f in done (how=how@entry=13) at end.c:1201
 #8  0x0000000017ca9c85 in done2 () at end.c:381
 #9  done2 () at end.c:337
 #10 0x0000000017c489da in doextcmd () at cmd.c:363
 #11 0x0000000017c57e94 in rhack (cmd=<optimized out>, cmd@entry=0x0) at cmd.c:4909
 #12 0x0000000017c265da in moveloop (resuming=<optimized out>) at allmain.c:435
 #13 0x0000000017e1b862 in main (argc=<optimized out>, argv=<optimized out>) at ../sys/unix/unixmain.c:351
status_window is NULL here. Simply checking for NULL avoids the problem. I added checks for the other windows as well, while I was there.
nhcopier pushed a commit that referenced this pull request Dec 23, 2024
If freedynamicdata() gets called twice, for whatever reason, a "double free" can occur.

warning: 44     ./nptl/pthread_kill.c: No such file or directory
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007ffff7c8b26e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007ffff7c6e8ff in __GI_abort () at ./stdlib/abort.c:79
#5  0x00007ffff7c6f7b6 in __libc_message_impl (fmt=fmt@entry=0x7ffff7e148d7 "%s\n")
    at ../sysdeps/posix/libc_fatal.c:132
#6  0x00007ffff7ceefe5 in malloc_printerr (str=str@entry=0x7ffff7e17bf0 "free(): double free detected in tcache 2")
    at ./malloc/malloc.c:5772
#7  0x00007ffff7cf154f in _int_free (av=0x7ffff7e49ac0 <main_arena>, p=<optimized out>, have_lock=0)
    at ./malloc/malloc.c:4541
#8  0x00007ffff7cf3d9e in __GI___libc_free (mem=0x555555ad82a0) at ./malloc/malloc.c:3398
#9  0x00005555557c12e9 in free_rect () at rect.c:48
#10 0x00005555557d77a2 in freedynamicdata () at save.c:1240
#11 0x0000555555682754 in nh_terminate (status=0) at end.c:1671
#12 0x000055555589af15 in opt_terminate () at ../sys/unix/unixmain.c:768
#13 0x000055555589af7a in after_opt_showpaths (dir=0x0) at ../sys/unix/unixmain.c:796
#14 0x0000555555693dd9 in do_deferred_showpaths (code=0) at files.c:4491
#15 0x0000555555778405 in initoptions () at options.c:6948
#16 0x0000555555899cd9 in main (argc=2, argv=0x7fffffffdad8) at ../sys/unix/unixmain.c:151
mbsperry pushed a commit to mbsperry/NetHackDCC that referenced this pull request Jul 14, 2026
The non-emscripten shim_player_selection was a no-op VDECLCB thunk, so a
game booted through the shim windowport never asked "Shall I pick
character's race, role, gender and alignment for you? [ynaq]" or any of
the role/race/gender/alignment menus -- role_init() silently random-rolled
every facet. Define it as a real function calling genl_player_setup(80),
like the emscripten branch, terminating on cancel the same way
genl_player_selection() does. The dialog rides the ordinary
yn_function/select_menu windowport calls, so shim hosts see it as regular
asks with no new protocol.

Log the patch as NetHack#5 in docs/engine-patches.md.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DaB4iuMLThWtuo2YwWZSvs
gagallo7 pushed a commit to gagallo7/Vulture-ng-NetHack-5.0 that referenced this pull request Jul 19, 2026
The base drag feature already let you grab a menu/dialog/inventory popup by
its frame and move it, but a click *outside* the foremost popup was silently
dropped -- you had to press Esc or hit Cancel to dismiss it.  Make an outside
left-click dismiss the popup, the conventional behaviour for a modal overlay.

During a modal popup's event loop the popup is the dispatcher's `topwin`, so a
press outside its bounds makes the hit-test (get_window_from_point) return NULL
-- the case that previously just returned V_EVENT_UNHANDLED.  Instead, when the
NULL hit-test comes from a genuine floating popup (topwin != ROOTWIN) on a left
button-down, synthesize an Esc key event and route it to the popup.  This reuses
each popup's own cancel path (menuwin -> V_MENU_CANCEL/ACCEPT, the dialogs ->
cancel, the wiki reader -> close) rather than hard-coding a per-type result, so
"click outside" == "press Esc" for every popup uniformly.

The gate is naturally safe: ROOTWIN spans the whole screen, so the hit-test is
never NULL during normal play (topwin is ROOTWIN there) -- the close only ever
fires for a real floating popup.  Dragging is unaffected: a press on the frame
hits target == the popup (win != NULL) and still starts a drag, and the drag's
button-up is consumed by the drag-capture branch before this code, so releasing
a drag outside the window doesn't spuriously re-close anything.

Compiles -Wall-clean; SDL-free suite 3771/0.  Runtime GUI pass still owed (no
display in the sandbox): open a menu, click off it -> it closes; drag it by the
frame -> still moves; click an item -> still selects.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CiAsr1eU8adevh7jJXik7B
gagallo7 pushed a commit to gagallo7/Vulture-ng-NetHack-5.0 that referenced this pull request Jul 19, 2026
… doc

Committed as 5264199ee: an outside click now dismisses the foremost floating
popup by synthesizing an Esc to it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CiAsr1eU8adevh7jJXik7B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants