Merge branch 'fix-mobj-reference-counting' into 'master'

Fix negative mobj reference counts all over the place

See merge request KartKrew/Kart!926
This commit is contained in:
toaster 2023-02-17 00:56:39 +00:00
commit c4b008e17e
3 changed files with 24 additions and 24 deletions

View file

@ -9532,7 +9532,7 @@ void K_KartEbrakeVisuals(player_t *p)
P_RemoveMobj(p->mo->hprev);
}
p->mo->hprev = P_SpawnMobj(p->mo->x, p->mo->y, p->mo->z, MT_HOLDBUBBLE);
P_SetTarget(&p->mo->hprev, P_SpawnMobj(p->mo->x, p->mo->y, p->mo->z, MT_HOLDBUBBLE));
p->mo->hprev->renderflags |= (RF_DONTDRAW & ~K_GetPlayerDontDrawFlag(p));
}
@ -9620,7 +9620,7 @@ void K_KartEbrakeVisuals(player_t *p)
if (p->mo->hprev && !P_MobjWasRemoved(p->mo->hprev) && (p->mo->hprev->frame & FF_FRAMEMASK) != 5)
{
P_RemoveMobj(p->mo->hprev);
p->mo->hprev = NULL;
P_SetTarget(&p->mo->hprev, NULL);
}
p->ebrakefor = 0;

View file

@ -49,20 +49,10 @@ tm_t tm = {0};
void P_RestoreTMStruct(tm_t tmrestore)
{
// Reference count management
if (tm.thing != tmrestore.thing)
{
P_SetTarget(&tm.thing, NULL);
}
if (tm.floorthing != tmrestore.floorthing)
{
P_SetTarget(&tm.floorthing, NULL);
}
if (tm.hitthing != tmrestore.hitthing)
{
P_SetTarget(&tm.hitthing, NULL);
}
// These are effectively a no-op if mobj remains the same
P_SetTarget(&tm.thing, tmrestore.thing);
P_SetTarget(&tm.floorthing, tmrestore.floorthing);
P_SetTarget(&tm.hitthing, tmrestore.hitthing);
// Restore state
tm = tmrestore;

View file

@ -5280,13 +5280,13 @@ void P_AddKartItem(mobj_t *thing)
// Keeps the hnext list from corrupting.
static void P_RemoveKartItem(mobj_t *thing)
{
mobj_t *mo;
for (mo = kitemcap; mo; mo = mo->itnext)
mobj_t *mo, **p;
for (mo = *(p = &kitemcap); mo; mo = *(p = &mo->itnext))
{
if (mo->itnext != thing)
if (mo != thing)
continue;
P_SetTarget(&mo->itnext, thing->itnext);
P_SetTarget(p, thing->itnext);
P_SetTarget(&thing->itnext, NULL);
return;
}
@ -5433,13 +5433,13 @@ static void P_AddOverlay(mobj_t *thing)
// Keeps the hnext list from corrupting.
static void P_RemoveOverlay(mobj_t *thing)
{
mobj_t *mo;
for (mo = overlaycap; mo; mo = mo->hnext)
mobj_t *mo, **p;
for (mo = *(p = &overlaycap); mo; mo = *(p = &mo->hnext))
{
if (mo->hnext != thing)
if (mo != thing)
continue;
P_SetTarget(&mo->hnext, thing->hnext);
P_SetTarget(p, thing->hnext);
P_SetTarget(&thing->hnext, NULL);
return;
}
@ -6469,6 +6469,9 @@ static void P_MobjSceneryThink(mobj_t *mobj)
break;
case MT_ITEMCAPSULE_PART:
P_ItemCapsulePartThinker(mobj);
if (P_MobjWasRemoved(mobj))
return;
break;
case MT_BATTLECAPSULE_PIECE:
if (mobj->extravalue2)
@ -9850,9 +9853,16 @@ void P_MobjThinker(mobj_t *mobj)
P_CheckMobjTrigger(mobj, false);
}
I_Assert(!P_MobjWasRemoved(mobj));
if (mobj->scale != mobj->destscale)
{
P_MobjScaleThink(mobj); // Slowly scale up/down to reach your destscale.
if (P_MobjWasRemoved(mobj))
return;
}
if (mobj->type == MT_GHOST && mobj->fuse > 0) // Not guaranteed to be MF_SCENERY or not MF_SCENERY!
{
if (mobj->extravalue1 > 0) // Sonic Advance 2 mode