Fix mobjcache memory leak after reloading gamestate

Weird history splice from 711804be
This commit is contained in:
Antonio Martinez 2024-10-07 16:59:51 -07:00 committed by Eidolon
parent b3086d011d
commit 7d584c1f79
3 changed files with 22 additions and 12 deletions

View file

@ -258,6 +258,7 @@ mobjtype_t P_GetMobjtype(UINT16 mthingtype);
void P_RespawnSpecials(void);
fixed_t P_GetMobjDefaultScale(mobj_t *mobj);
mobj_t *P_AllocateMobj(void);
mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type);
void P_CalculatePrecipFloor(precipmobj_t *mobj);

View file

@ -10844,6 +10844,24 @@ static void P_DefaultMobjShadowScale(mobj_t *thing)
}
}
mobj_t *P_AllocateMobj(void)
{
mobj_t *mobj;
if (mobjcache != NULL)
{
mobj = mobjcache;
mobjcache = mobjcache->hnext;
memset(mobj, 0, sizeof(*mobj));
}
else
{
mobj = Z_Calloc(sizeof (*mobj), PU_LEVEL, NULL);
}
return mobj;
}
//
// P_SpawnMobj
//
@ -10870,16 +10888,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type)
type = MT_RAY;
}
if (mobjcache != NULL)
{
mobj = mobjcache;
mobjcache = mobjcache->hnext;
memset(mobj, 0, sizeof(*mobj));
}
else
{
mobj = Z_Calloc(sizeof (*mobj), PU_LEVEL, NULL);
}
mobj = P_AllocateMobj();
// this is officially a mobj, declared as soon as possible.
mobj->thinker.function.acp1 = (actionf_p1)P_MobjThinker;

View file

@ -4511,13 +4511,13 @@ static thinker_t* LoadMobjThinker(savebuffer_t *save, actionf_p1 thinker)
return NULL;
}
mobj = (mobj_t*)Z_Calloc(sizeof (*mobj), PU_LEVEL, NULL);
mobj = P_AllocateMobj();
mobj->spawnpoint = &mapthings[spawnpointnum];
mapthings[spawnpointnum].mobj = mobj;
}
else
mobj = (mobj_t*)Z_Calloc(sizeof (*mobj), PU_LEVEL, NULL);
mobj = P_AllocateMobj();
// declare this as a valid mobj as soon as possible.
mobj->thinker.function.acp1 = thinker;