From f05f040cea7ae5f32b58cc431d75301b5e76bd55 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 14 Feb 2023 00:46:54 -0800 Subject: [PATCH 1/6] Fix faulty assertions --- src/g_game.c | 2 +- src/lua_infolib.c | 4 ---- src/m_cond.c | 2 +- src/screen.c | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index d933b5a80..798db2536 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4236,7 +4236,7 @@ static void G_DoContinued(void) { player_t *pl = &players[consoleplayer]; I_Assert(!netgame && !multiplayer); - I_Assert(pl->continues > 0); + //I_Assert(pl->continues > 0); /*if (pl->continues) pl->continues--;*/ diff --git a/src/lua_infolib.c b/src/lua_infolib.c index 0c90dd00f..71eff8784 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -537,8 +537,6 @@ static int pivotlist_get(lua_State *L) spriteinfo_t *sprinfo = *((spriteinfo_t **)luaL_checkudata(L, 1, META_PIVOTLIST)); UINT8 frame = GetPivotFrame(L, 2); - I_Assert(framepivot != NULL); - // bypass LUA_PushUserdata container = lua_newuserdata(L, sizeof *container); container->sprinfo = sprinfo; @@ -563,8 +561,6 @@ static int pivotlist_set(lua_State *L) if (hook_cmd_running) return luaL_error(L, "Do not alter spriteframepivot_t in CMD building code!"); - I_Assert(pivotlist != NULL); - frame = GetPivotFrame(L, 2); // pivot[] is a table diff --git a/src/m_cond.c b/src/m_cond.c index 4f0a9126a..abc228d3a 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -429,7 +429,7 @@ void M_AddRawCondition(UINT8 set, UINT8 id, conditiontype_t c, INT32 r, INT16 x1 condition_t *cond; UINT32 num, wnum; - I_Assert(set && set <= MAXCONDITIONSETS); + I_Assert(set < MAXCONDITIONSETS); wnum = conditionSets[set].numconditions; num = ++conditionSets[set].numconditions; diff --git a/src/screen.c b/src/screen.c index 9b1036d7c..2b78d03f1 100644 --- a/src/screen.c +++ b/src/screen.c @@ -234,7 +234,7 @@ void R_SetColumnFunc(size_t id, boolean brightmapped) void R_SetSpanFunc(size_t id, boolean npo2, boolean brightmapped) { - I_Assert(id < COLDRAWFUNC_MAX); + I_Assert(id < SPANDRAWFUNC_MAX); if (spanfuncs_npo2[id] != NULL && npo2 == true) { From 0b2273b8481f0b20a8fcc9e31635dfe030a17cc5 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 14 Feb 2023 02:45:26 -0800 Subject: [PATCH 2/6] p_saveg.c: replace unknown thinker error with assert It is undefined behavior to cast function pointer to void*. --- src/p_saveg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index b7f57514e..0420d0520 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -3135,8 +3135,8 @@ static void P_NetArchiveThinkers(savebuffer_t *save) continue; } #ifdef PARANOIA - else if (th->function.acp1 != (actionf_p1)P_RemoveThinkerDelayed) // wait garbage collection - I_Error("unknown thinker type %p", th->function.acp1); + else + I_Assert(th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed); // wait garbage collection #endif } From 98a4a90129b4ce2784982b2d5f87d96adf837e18 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 14 Feb 2023 00:49:19 -0800 Subject: [PATCH 3/6] PARANOIA: do mobj scramble last --- src/p_mobj.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index e5b125bb8..b773134b9 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -11190,12 +11190,6 @@ void P_RemoveMobj(mobj_t *mobj) P_SetTarget(&mobj->itnext, NULL); - // DBG: set everything in mobj_t to 0xFF instead of leaving it. debug memory error. -#ifdef SCRAMBLE_REMOVED - // Invalidate mobj_t data to cause crashes if accessed! - memset((UINT8 *)mobj + sizeof(thinker_t), 0xff, sizeof(mobj_t) - sizeof(thinker_t)); -#endif - P_RemoveThingTID(mobj); R_RemoveMobjInterpolator(mobj); @@ -11215,6 +11209,12 @@ void P_RemoveMobj(mobj_t *mobj) } P_RemoveThinker((thinker_t *)mobj); + + // DBG: set everything in mobj_t to 0xFF instead of leaving it. debug memory error. +#ifdef SCRAMBLE_REMOVED + // Invalidate mobj_t data to cause crashes if accessed! + memset((UINT8 *)mobj + sizeof(thinker_t), 0xff, sizeof(mobj_t) - sizeof(thinker_t)); +#endif } // This does not need to be added to Lua. From 1d688c3417465014494ecfbe387598c889df63f4 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 14 Feb 2023 03:39:51 -0800 Subject: [PATCH 4/6] sdl/i_system.c: add -nofork option to disable forking signal handler --- src/sdl/i_system.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 515dc3e95..352313071 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1700,7 +1700,10 @@ INT32 I_StartupSystem(void) #endif I_StartupConsole(); #ifdef NEWSIGNALHANDLER - I_Fork(); + // This is useful when debugging. It lets GDB attach to + // the correct process easily. + if (!M_CheckParm("-nofork")) + I_Fork(); #endif I_RegisterSignals(); I_OutputMsg("Compiled for SDL version: %d.%d.%d\n", @@ -1993,9 +1996,10 @@ void I_ShutdownSystem(void) { INT32 c; -#ifndef NEWSIGNALHANDLER - I_ShutdownConsole(); +#ifdef NEWSIGNALHANDLER + if (M_CheckParm("-nofork")) #endif + I_ShutdownConsole(); for (c = MAX_QUIT_FUNCS-1; c >= 0; c--) if (quit_funcs[c]) From a77234233bd8b372d3e2f4d245f9db97e2c5807d Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 14 Feb 2023 04:07:47 -0800 Subject: [PATCH 5/6] doomdef.h: enable most debugging ifndef NDEBUG --- src/doomdef.h | 8 ++++++++ src/z_zone.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/doomdef.h b/src/doomdef.h index 5318ee3e7..be24fefda 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -103,6 +103,14 @@ extern "C" { //#define NOMD5 +// If you don't disable ALL debug first, you get ALL debug enabled +#if !defined (NDEBUG) +#define PACKETDROP +#define PARANOIA +#define RANGECHECK +#define ZDEBUG +#endif + // Uncheck this to compile debugging code //#define RANGECHECK //#ifndef PARANOIA diff --git a/src/z_zone.h b/src/z_zone.h index d45fde9b3..5132c0d55 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -15,6 +15,7 @@ #define __Z_ZONE__ #include +#include "doomdef.h" #include "doomtype.h" #ifdef __cplusplus From 2e3ed95338363702b40995c96faeed5fe33f5725 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 14 Feb 2023 04:10:58 -0800 Subject: [PATCH 6/6] Add assert command to test whether assertions are enabled at runtime --- src/d_main.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/d_main.c b/src/d_main.c index 38c16bc39..2e3f70980 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1196,6 +1196,15 @@ const char *D_GetFancyBranchName(void) return compbranch; } +static void Command_assert(void) +{ +#if !defined(NDEBUG) || defined(PARANOIA) + CONS_Printf("Yes, assertions are enabled.\n"); +#else + CONS_Printf("No, ssertions are NOT enabled.\n"); +#endif +} + // // D_SRB2Main // @@ -1387,6 +1396,8 @@ void D_SRB2Main(void) // Do this up here so that WADs loaded through the command line can use ExecCfg COM_Init(); + COM_AddCommand("assert", Command_assert); + #ifndef TESTERS // add any files specified on the command line with -file wadfile // to the wad list