fixed GC handling of players.

These were missing null checks, the player pointers also weren't nulled after deleting the objects.
This commit is contained in:
Christoph Oelckers 2023-10-02 19:03:27 +02:00
parent 049bd41efe
commit 1ce8ceac5d
7 changed files with 58 additions and 37 deletions

View file

@ -635,7 +635,11 @@ int GameMain()
if (gi) if (gi)
{ {
gi->FreeLevelData(); gi->FreeLevelData();
for (int i = 0; i < MAXPLAYERS; i++) delete PlayerArray[i]; for (int i = 0; i < MAXPLAYERS; i++)
{
delete PlayerArray[i];
PlayerArray[i] = nullptr;
}
} }
DestroyAltHUD(); DestroyAltHUD();
DeinitMenus(); DeinitMenus();

View file

@ -98,12 +98,16 @@ static void markgcroots()
MarkSprInSect(); MarkSprInSect();
for (int i = 0; i < MAXPLAYERS; i++) for (int i = 0; i < MAXPLAYERS; i++)
{ {
GC::Mark(getPlayer(i)->actor); auto plr = getPlayer(i);
GC::MarkArray(getPlayer(i)->ctfFlagState, 2); if (plr)
GC::Mark(getPlayer(i)->aimTarget); {
GC::MarkArray(getPlayer(i)->aimTargets, 16); GC::Mark(plr->actor);
GC::Mark(getPlayer(i)->fragger); GC::MarkArray(plr->ctfFlagState, 2);
GC::Mark(getPlayer(i)->voodooTarget); GC::Mark(plr->aimTarget);
GC::MarkArray(plr->aimTargets, 16);
GC::Mark(plr->fragger);
GC::Mark(plr->voodooTarget);
}
} }
for (auto& evobj : rxBucket) for (auto& evobj : rxBucket)
{ {

View file

@ -85,18 +85,22 @@ static void markgcroots()
GC::Mark(ud.cameraactor); GC::Mark(ud.cameraactor);
for (int i = 0; i < MAXPLAYERS; i++) for (int i = 0; i < MAXPLAYERS; i++)
{ {
GC::Mark(getPlayer(i)->actor); auto plr = getPlayer(i);
GC::Mark(getPlayer(i)->actorsqu); if (plr)
GC::Mark(getPlayer(i)->wackedbyactor);
GC::Mark(getPlayer(i)->on_crane);
GC::Mark(getPlayer(i)->holoduke_on);
GC::Mark(getPlayer(i)->somethingonplayer);
GC::Mark(getPlayer(i)->access_spritenum);
GC::Mark(getPlayer(i)->dummyplayersprite);
GC::Mark(getPlayer(i)->newOwner);
for (auto& var : getPlayer(i)->uservars)
{ {
var.Mark(); GC::Mark(plr->actor);
GC::Mark(plr->actorsqu);
GC::Mark(plr->wackedbyactor);
GC::Mark(plr->on_crane);
GC::Mark(plr->holoduke_on);
GC::Mark(plr->somethingonplayer);
GC::Mark(plr->access_spritenum);
GC::Mark(plr->dummyplayersprite);
GC::Mark(plr->newOwner);
for (auto& var : plr->uservars)
{
var.Mark();
}
} }
} }
} }

View file

@ -83,16 +83,20 @@ int nCurStartSprite;
size_t MarkPlayers() size_t MarkPlayers()
{ {
for (int i = 0; i < kMaxWeapons; i++) for (int i = 0; i < MAXPLAYERS; i++)
{ {
GC::Mark(getPlayer(i)->actor); auto plr = getPlayer(i);
GC::Mark(getPlayer(i)->pDoppleSprite); if (plr)
GC::Mark(getPlayer(i)->pPlayerFloorSprite); {
GC::Mark(getPlayer(i)->pPlayerGrenade); GC::Mark(plr->actor);
GC::Mark(getPlayer(i)->pTarget); GC::Mark(plr->pDoppleSprite);
GC::Mark(plr->pPlayerFloorSprite);
GC::Mark(plr->pPlayerGrenade);
GC::Mark(plr->pTarget);
}
} }
GC::MarkArray(nNetStartSprite, kMaxPlayers); GC::MarkArray(nNetStartSprite, MAXPLAYERS);
return 6 * kMaxPlayers; return 6 * MAXPLAYERS;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View file

@ -120,14 +120,18 @@ void markgcroots()
GC::MarkArray(BossSpriteNum, 3); GC::MarkArray(BossSpriteNum, 3);
for (int i = 0; i < MAXPLAYERS; i++) for (int i = 0; i < MAXPLAYERS; i++)
{ {
GC::Mark(getPlayer(i)->actor); auto plr = getPlayer(i);
GC::Mark(getPlayer(i)->lowActor); if (plr)
GC::Mark(getPlayer(i)->highActor); {
GC::Mark(getPlayer(i)->remoteActor); GC::Mark(plr->actor);
GC::Mark(getPlayer(i)->PlayerUnderActor); GC::Mark(plr->lowActor);
GC::Mark(getPlayer(i)->KillerActor); GC::Mark(plr->highActor);
GC::Mark(getPlayer(i)->HitBy); GC::Mark(plr->remoteActor);
GC::Mark(getPlayer(i)->last_camera_act); GC::Mark(plr->PlayerUnderActor);
GC::Mark(plr->KillerActor);
GC::Mark(plr->HitBy);
GC::Mark(plr->last_camera_act);
}
} }
for (auto& so : SectorObject) for (auto& so : SectorObject)
{ {

View file

@ -71,6 +71,8 @@ struct PACKINFO // not native!
struct BloodPlayer native struct BloodPlayer native
{ {
native uint8 pnum; // Connect id
native int GetHealth(); // health is stored in the XSPRITE which cannot be safely exported to scripting at the moment due to pending refactoring. native int GetHealth(); // health is stored in the XSPRITE which cannot be safely exported to scripting at the moment due to pending refactoring.
native int powerupCheck(int pwup); native int powerupCheck(int pwup);
//DUDEINFO* pDudeInfo; //DUDEINFO* pDudeInfo;
@ -89,7 +91,6 @@ struct BloodPlayer native
native int swayAmp; native int swayAmp;
native double swayHeight; native double swayHeight;
native double swayWidth; native double swayWidth;
native int nPlayer; // Connect id
//native int nSprite; //native int nSprite;
native int lifeMode; native int lifeMode;
native double zView; native double zView;

View file

@ -147,6 +147,8 @@ struct SW native
struct SWPlayer native struct SWPlayer native
{ {
native uint8 pnum; // carry along the player number
// variable that fit in the sprite or user structure // variable that fit in the sprite or user structure
/* /*
union union
@ -217,8 +219,6 @@ struct SWPlayer native
native double RevolveDeltaAng; native double RevolveDeltaAng;
native int16 pnum; // carry along the player number
//native int16 LadderSector; //native int16 LadderSector;
native int16 JumpDuration; native int16 JumpDuration;
native int16 WadeDepth; native int16 WadeDepth;