fix reported crash of TTY_PERM_INVENT segfaulting

Options processing can be early, even before ttyDisplay is allocated.
If we find that TTY_PERM_INVENT initialization is happening too early,
just set a marker (iflags.perm_invent_pending) to try again a bit later.

The changes in win/share are just to be able to sucessfully
reproduce the original issue on Windows. It was easily reproduced
on Unix, just by building with TTY_PERM_INVENT in include/config.h
and setting OPTIONS=perm_invent in config file.
This commit is contained in:
nhmall
2025-01-02 11:46:15 -05:00
parent 2d4f9893ad
commit d3c57e1b42
8 changed files with 74 additions and 16 deletions

View File

@@ -720,6 +720,10 @@ init_sound_disp_gamewindows(void)
display_nhwindow(WIN_MESSAGE, FALSE);
clear_glyph_buffer();
display_nhwindow(WIN_MAP, FALSE);
#ifdef TTY_PERM_INVENT
if (iflags.perm_invent_pending)
check_perm_invent_again();
#endif
}
void

View File

@@ -6149,6 +6149,12 @@ sync_perminvent(void)
|| in_perm_invent_toggled) {
wri = ctrl_nhwindow(WIN_INVEN, request_settings, &wri_info);
if (wri != 0) {
if ((wri->tocore.tocore_flags & (too_early)) != 0) {
/* don't be too noisy about this as it's really
* a startup timing issue. Just set a marker. */
iflags.perm_invent_pending = TRUE;
return;
}
if ((wri->tocore.tocore_flags & (too_small | prohibited))
!= 0) {
/* sizes aren't good enough */

View File

@@ -5384,7 +5384,11 @@ can_set_perm_invent(void)
iflags.perminv_mode = InvOptOn;
#ifdef TTY_PERM_INVENT
if (WINDOWPORT(tty) && !go.opt_initial) {
if ((WINDOWPORT(tty)
#ifdef WIN32
|| WINDOWPORT(safestartup)
#endif
) && !go.opt_initial) {
perm_invent_toggled(FALSE);
/* perm_invent_toggled()
-> sync_perminvent()
@@ -5401,6 +5405,20 @@ can_set_perm_invent(void)
return TRUE;
}
#ifdef TTY_PERM_INVENT
void
check_perm_invent_again(void)
{
if (iflags.perm_invent_pending) {
iflags.perm_invent = FALSE;
if (can_set_perm_invent())
iflags.perm_invent = TRUE;
iflags.perm_invent_pending = FALSE;
}
}
#endif
staticfn int
handler_menustyle(void)
{