diff --git a/src/d_main.c b/src/d_main.c index 594829261..e6568030e 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -147,7 +147,7 @@ INT32 eventhead, eventtail; boolean dedicated = false; -boolean loaded_config = false; +boolean loaded_config = false; // true once config.cfg loaded AND executed // // D_PostEvent @@ -1881,7 +1881,9 @@ void D_SRB2Main(void) savedata.lives = 0; // flag this as not-used - loaded_config = true; // so pallettechange doesent get called 500 times at startup lol + // make sure I_Quit() will write back the correct config + // (do not write back the config if it crash before) + loaded_config = true; // so palettechange doesent get called 500 times at startup lol //------------------------------------------------ COMMAND LINE PARAMS diff --git a/src/d_netcmd.c b/src/d_netcmd.c index c0a7bfb93..90f98f179 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -753,6 +753,11 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_killingdead); // d_clisrv +#ifndef NONET +#ifdef SATURNJOIN + CV_RegisterVar(&cv_allownewsaturnplayer); // need to register it before cv_maxplayers && cv_allownewplayer +#endif +#endif CV_RegisterVar(&cv_maxplayers); CV_RegisterVar(&cv_resynchattempts); #ifdef SATURNPAK @@ -766,9 +771,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_httpsource); #ifndef NONET CV_RegisterVar(&cv_allownewplayer); -#ifdef SATURNJOIN - CV_RegisterVar(&cv_allownewsaturnplayer); -#endif + CV_RegisterVar(&cv_joinrefusemessage); CV_RegisterVar(&cv_chatlogsize); #ifdef VANILLAJOINNEXTROUND diff --git a/src/d_think.h b/src/d_think.h index 6b8ee113a..8177f464d 100644 --- a/src/d_think.h +++ b/src/d_think.h @@ -17,6 +17,8 @@ #ifndef __D_THINK__ #define __D_THINK__ +#include "doomdef.h" + #ifdef __GNUG__ #pragma interface #endif @@ -50,6 +52,10 @@ typedef struct thinker_s // this one using pointers. Used for garbage collection. INT32 references; boolean cachable; +#ifdef PARANOIA + INT32 debug_mobjtype; + tic_t debug_time; +#endif } thinker_t; #endif diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 554c2297a..85e50465a 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -624,7 +624,7 @@ static void HWR_PrecacheLevelFlats(void) // gotta check sector floor and ceiling for (j = 0; j < 2; j++) { - const boolean ceiling = (j == 1); + const boolean ceiling = (j == 0); INT32 pic = ceiling ? sec->ceilingpic : sec->floorpic; levelflat = levelflats[pic]; diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index 98a4890b1..a9c9d93b7 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -337,7 +337,6 @@ static UINT64 GetItemId(void) #else // he who controls the JIT controls the API const void *p = lua_getpc(gL, 1); - I_Assert(p != NULL); UINT64 id = (uintptr_t)p; #endif // leave bits 0 and 1 free for the string mode diff --git a/src/m_misc.c b/src/m_misc.c index ca4b745ed..ff9892464 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -443,7 +443,6 @@ char configfile[MAX_WADPATH]; // ========================================================================== // CONFIGURATION // ========================================================================== -static boolean gameconfig_loaded = false; // true once config.cfg loaded AND executed /** Saves a player's config, possibly to a particular file. * @@ -548,10 +547,6 @@ void M_FirstLoadConfig(void) // don't filter anymore vars and don't let this convsvar be changed COM_BufInsertText(va("%s \"%d\"\n", cv_execversion.name, EXECVERSION)); CV_ToggleExecVersion(false); - - // make sure I_Quit() will write back the correct config - // (do not write back the config if it crash before) - gameconfig_loaded = true; } /** Saves the game configuration. @@ -565,7 +560,7 @@ void M_SaveConfig(const char *filename) char backupfile[MAX_WADPATH+4]; // make sure not to write back the config until it's been correctly loaded - if (!gameconfig_loaded) + if (!loaded_config) return; // Create backup of the config file diff --git a/src/p_mobj.c b/src/p_mobj.c index a743f05fc..fb34b335d 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -10132,6 +10132,10 @@ void P_RemoveMobj(mobj_t *mobj) { // Add thinker just to delay removing it until refrences are gone. mobj->flags &= ~MF_NOTHINK; P_AddThinker((thinker_t *)mobj); +#ifdef PARANOIA + // Saved to avoid being scrambled like below... + mobj->thinker.debug_mobjtype = mobj->type; +#endif #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)); @@ -10141,6 +10145,10 @@ void P_RemoveMobj(mobj_t *mobj) } else { +#ifdef PARANOIA + // Saved to avoid being scrambled like below... + mobj->thinker.debug_mobjtype = mobj->type; +#endif #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)); @@ -10163,8 +10171,10 @@ void P_FreePrecipMobj(precipmobj_t *mobj) // Clearing out stuff for savegames void P_RemoveSavegameMobj(mobj_t *mobj) { + thinker_t *th = (thinker_t*)mobj; + // unlink from sector and block lists - if (((thinker_t *)mobj)->function.acp1 == (actionf_p1)P_NullPrecipThinker) + if (th->function.acp1 == (actionf_p1)P_NullPrecipThinker) { P_UnsetPrecipThingPosition((precipmobj_t *)mobj); } @@ -10185,9 +10195,13 @@ void P_RemoveSavegameMobj(mobj_t *mobj) S_StopSound(mobj); R_RemoveMobjInterpolator(mobj); + // just set its reference count to 0 to not trigger the assert in P_UnlinkThinker + if (th->references != 0) + th->references = 0; + // free block // Here we use the same code as R_RemoveThinkerDelayed, but without reference counting (we're removing everything so it shouldn't matter) and without touching currentthinker since we aren't in P_RunThinkers - P_UnlinkThinker((thinker_t*)mobj); + P_UnlinkThinker(th); } static CV_PossibleValue_t respawnitemtime_cons_t[] = {{1, "MIN"}, {300, "MAX"}, {0, NULL}}; diff --git a/src/p_polyobj.c b/src/p_polyobj.c index 61c08a05d..629595068 100644 --- a/src/p_polyobj.c +++ b/src/p_polyobj.c @@ -156,6 +156,9 @@ FUNCINLINE static ATTRINLINE void PolyObj_AddThinker(thinker_t *th) th->references = 0; th->cachable = false; // not initialising this made the mobjcache die thx! +#ifdef PARANOIA + th->debug_mobjtype = MT_NULL; +#endif } static void FreeSideLists(void) diff --git a/src/p_sight.c b/src/p_sight.c index 5dfc796b8..b02ffd786 100644 --- a/src/p_sight.c +++ b/src/p_sight.c @@ -34,6 +34,7 @@ typedef struct { static INT32 sightcounts[2]; typedef INT32 (*divlinefunc)(fixed_t x, fixed_t y, const divline_t *node); +typedef INT32 (*divlinecrossfunc)(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2, const divline_t *node); // // P_DivlineSide @@ -67,6 +68,11 @@ static inline INT32 P_DivlineCrossed(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t return (P_DivlineSide(x1, y1, node) == P_DivlineSide(x2, y2, node)); } +static inline INT32 P_DivlineCrossedFast(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2, const divline_t *node) +{ + return (P_DivlineSideFast(x1, y1, node) == P_DivlineSideFast(x2, y2, node)); +} + static boolean P_CrossSubsecPolyObj(polyobj_t *po, register los_t *los) { size_t i; @@ -130,7 +136,7 @@ static boolean P_CrossSubsecPolyObj(polyobj_t *po, register los_t *los) // // Returns true if strace crosses the given subsector successfully. // -static boolean P_CrossSubsector(size_t num, register los_t *los) +static boolean P_CrossSubsector(size_t num, register los_t *los, boolean fast) { seg_t *seg; INT32 count; @@ -159,6 +165,8 @@ static boolean P_CrossSubsector(size_t num, register los_t *los) } } + const divlinecrossfunc divlinecrossFunc = fast ? P_DivlineCrossedFast : P_DivlineCrossed; + for (count = subsectors[num].numlines; --count >= 0; seg++) // check lines { line_t *line = seg->linedef; @@ -187,14 +195,14 @@ static boolean P_CrossSubsector(size_t num, register los_t *los) v2 = line->v2; // line isn't crossed? - if (P_DivlineCrossed(v1->x, v1->y, v2->x, v2->y, &los->strace)) + if (divlinecrossFunc(v1->x, v1->y, v2->x, v2->y, &los->strace)) continue; divl.dx = v2->x - (divl.x = v1->x); divl.dy = v2->y - (divl.y = v1->y); // line isn't crossed? - if (P_DivlineCrossed(los->strace.x, los->strace.y, los->t2x, los->t2y, &divl)) + if (divlinecrossFunc(los->strace.x, los->strace.y, los->t2x, los->t2y, &divl)) continue; // stop because it is not two sided anyway @@ -326,7 +334,7 @@ static boolean P_CrossBSPNode(INT32 bspnum, register los_t *los, boolean fast) } } - return P_CrossSubsector((bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR), los); + return P_CrossSubsector((bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR), los, fast); } // diff --git a/src/p_tick.c b/src/p_tick.c index 8fbdf8b6a..212c2f1e6 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -11,6 +11,10 @@ /// \file p_tick.c /// \brief Archiving: SaveGame I/O, Thinker, Ticker +#ifdef PARANOIA +#include "dehacked.h" // MOBJTYPE_LIST +#endif + #include "doomstat.h" #include "g_game.h" #include "g_input.h" @@ -204,6 +208,9 @@ void P_AddThinker(thinker_t *thinker) thinker->references = 0; // killough 11/98: init reference counter to 0 thinker->cachable = (thinker->function.acp1 == (actionf_p1)P_MobjThinker); +#ifdef PARANOIA + thinker->debug_mobjtype = MT_NULL; +#endif } // @@ -220,8 +227,48 @@ void P_AddPrecipThinker(thinker_t *thinker) thinker->references = 0; // killough 11/98: init reference counter to 0 thinker->cachable = false; +#ifdef PARANOIA + thinker->debug_mobjtype = MT_NULL; +#endif } +#ifdef PARANOIA +static const char *MobjTypeName(const mobj_t *mobj) +{ + actionf_p1 p1 = mobj->thinker.function.acp1; + + if (p1 == (actionf_p1)P_MobjThinker) + { + return MOBJTYPE_LIST[mobj->type]; + } + else if (p1 == (actionf_p1)P_RemoveThinkerDelayed) + { + if (mobj->thinker.debug_mobjtype != MT_NULL) + { + return MOBJTYPE_LIST[mobj->thinker.debug_mobjtype]; + } + } + + return ""; +} + +static const char *MobjThinkerName(const mobj_t *mobj) +{ + actionf_p1 p1 = mobj->thinker.function.acp1; + + if (p1 == (actionf_p1)P_MobjThinker) + { + return "P_MobjThinker"; + } + else if (p1 == (actionf_p1)P_RemoveThinkerDelayed) + { + return "P_RemoveThinkerDelayed"; + } + + return ""; +} +#endif + // // killough 11/98: // @@ -242,34 +289,46 @@ static thinker_t *currentthinker; // void P_RemoveThinkerDelayed(thinker_t *thinker) { + if (thinker->references != 0) + { #ifdef PARANOIA - if (thinker->next) - thinker->next = NULL; - else if (thinker->references) // Usually gets cleared up in one frame; what's going on here, then? - CONS_Printf("Number of potentially faulty references: %d\n", thinker->references); + // Removed mobjs can be the target of another mobj. In + // that case, the other mobj will manage its reference + // to the removed mobj in P_MobjThinker. However, if + // the removed mobj is removed after the other object + // thinks, the reference management is delayed by one + // tic (or two?) + const UINT8 delay = 2; + + if (thinker->debug_time > leveltime) + { + thinker->debug_time = leveltime + delay + 1; // do not print errors again + } + else if ((thinker->debug_time + delay) <= leveltime) + { + CONS_Printf( + "PARANOIA/P_RemoveThinkerDelayed: %p %s references=%d\n", + (void*)thinker, + MobjTypeName((mobj_t*)thinker), + thinker->references + ); + + thinker->debug_time = leveltime + delay + 1; // do not print this error again + } #endif - if (thinker->references) return; + } + + R_DestroyLevelInterpolators(thinker); - /* Remove from main thinker list */ - thinker_t *next = thinker->next; /* Note that currentthinker is guaranteed to point to us, * and since we're freeing our memory, we had better change that. So * point it to thinker->prev, so the iterator will correctly move on to * thinker->prev->next = thinker->next */ - (next->prev = currentthinker = thinker->prev)->next = next; - R_DestroyLevelInterpolators(thinker); + currentthinker = thinker->prev; - if (thinker->cachable == true) - { - // put cachable thinkers in the mobj cache, so we can avoid allocations - ((mobj_t *)thinker)->hnext = mobjcache; - mobjcache = (mobj_t *)thinker; - } - else - { - Z_Free(thinker); - } + /* Remove from main thinker list */ + P_UnlinkThinker(thinker); } // @@ -327,12 +386,45 @@ void P_RemoveThinker(thinker_t *thinker) * references, and delay removal until the count is 0. */ -mobj_t *P_SetTarget(mobj_t **mop, mobj_t *targ) +mobj_t *P_SetTarget2(mobj_t **mop, mobj_t *targ +#ifdef PARANOIA + , const char *source_file, int source_line +#endif +) { - if (*mop) // If there was a target already, decrease its refcount + if (*mop) // If there was a target already, decrease its refcount + { (*mop)->thinker.references--; - if ((*mop = targ) != NULL) // Set new target and if non-NULL, increase its counter + +#ifdef PARANOIA + if ((*mop)->thinker.references < 0) + { + CONS_Printf( + "PARANOIA/P_SetTarget: %p %s %s references=%d, references go negative! (%s:%d)\n", + (void*)*mop, + MobjTypeName(*mop), + MobjThinkerName(*mop), + (*mop)->thinker.references, + source_file, + source_line + ); + } + + (*mop)->thinker.debug_time = leveltime; +#endif + } + + if (targ != NULL) // Set new target and if non-NULL, increase its counter + { targ->thinker.references++; + +#ifdef PARANOIA + targ->thinker.debug_time = leveltime; +#endif + } + + *mop = targ; + return targ; } diff --git a/src/p_tick.h b/src/p_tick.h index 11b5889ed..a903be0fd 100644 --- a/src/p_tick.h +++ b/src/p_tick.h @@ -14,6 +14,8 @@ #ifndef __P_TICK__ #define __P_TICK__ +#include "doomdef.h" + #ifdef __GNUG__ #pragma interface #endif @@ -29,6 +31,16 @@ void P_Ticker(boolean run); void P_PreTicker(INT32 frames); void P_DoTeamscrambling(void); void P_RemoveThinkerDelayed(thinker_t *thinker); -mobj_t *P_SetTarget(mobj_t **mo, mobj_t *target); // killough 11/98 +mobj_t *P_SetTarget2(mobj_t **mo, mobj_t *target +#ifdef PARANOIA +, const char *source_file, int source_line +#endif +); + +#ifdef PARANOIA +#define P_SetTarget(...) P_SetTarget2(__VA_ARGS__, __FILE__, __LINE__) +#else +#define P_SetTarget P_SetTarget2 +#endif #endif