why wouldnt this work? im trying to add the setting RESPAWN_PLAYER_RANDOM that will use grid.leastDangerousSpawnPoint or whatever. it seems to work, it spawns the player, but upon round end the server crashes and says "Segmentation Fault". i basically copied the code from RESPAWN_PLAYER in sty+ct, and used the least dangerous spawn point thing. here is the block of code (btw its in the file src/tron/gWinZone.cpp):
Tank: exactly what i thought, some kind of left over objects.
i pretty much got it all from RESPAWN_PLAYER, i didnt take out anything that said addobject interesting this or anything. idk. ill look again.
// let's respawn now ...
eGameObject *pGameObject = pPlayer->Object();
if ((!pGameObject) ||
(!(pGameObject->Alive()) ))
If pGameObject is NULL, the first condition is true so the second isn't checked (well, I guess so).
In the case it is not NULL but it is pointing to a broken address, the program continues checking for pGameObject->Alive() causing a segmentation fault.
// let's respawn now ...
eGameObject *pGameObject = pPlayer->Object();
if ((!pGameObject) ||
(!(pGameObject->Alive()) ))
If pGameObject is NULL, the first condition is true so the second isn't checked (well, I guess so).
In the case it is not NULL but it is pointing to a broken address, the program continues checking for pGameObject->Alive() causing a segmentation fault.
But as long as the player pointer is OK, the Object() pointer is also guaranteed to be either NULL or pointing to a valid object. And the player pointer comes straight out of a search, so should be OK.
I'm afraid you'll need to fire up gdb and look deeper into the crash. Do (without the bits after #):
gdb ./armagetronad-dedicated # launch gdb
r # start
(play on the server, use the command, wait for crash)
bt full # full backtrace, all functions currently in use, all variables
Z-Man wrote:But as long as the player pointer is OK, the Object() pointer is also guaranteed to be either NULL or pointing to a valid object.
Is it really guaranteed?
I'll post my case so you can judge if it's a similar case or not, since I can't be sure of that.
My server crashed occasionally, only with many players, and only if someone died in a deathzone. That started happening once i've added this condition in a function called every second from gGame::Analysis:
for ( int i = 0; i < se_PlayerNetIDs.Len(); i ++ ) // count who reached the end and is alive
{
ePlayerNetID * p = se_PlayerNetIDs[i];
if ( p->raceArrived && p->IsHuman() && p->Object()->Alive())
arrivedAlive ++;
}
for ( int i = 0; i < se_PlayerNetIDs.Len(); i ++ ) // count who reached the end and is alive
{
ePlayerNetID * p = se_PlayerNetIDs[i];
if ( p->raceArrived && p->IsHuman() && p->Object() != NULL )
{
if ( p->Object()->Alive() )
arrivedAlive ++;
}
}
Well, yes ePlayerNetID()::Object() returns NULL or a valid object. Your problems were with the missing check for NULL, while Ivantis' code has that check.