Issue with coding

What do you want to see in Armagetron soon? Any new feature ideas? Let's ponder these ground breaking ideas...
User avatar
ivantis
Round Winner
Posts: 269
Joined: Mon Mar 03, 2008 2:33 pm
Contact:

Issue with coding

Post by ivantis »

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):

Code: Select all

static void sg_RespawnRand(std::istream &s)
{
	gArena arena = Arena;
        eGrid *grid = eGrid::CurrentGrid();
        if(!grid) {
                con << "Must be called while a grid exists!\n";
                return;
        }

        tString params;
        params.ReadLine( s, true );
        int pos = 0;
        tString PlayerName = ePlayerNetID::FilterName(params.ExtractNonBlankSubString(pos));
        ePlayerNetID *pPlayer = 0;
        pPlayer = ePlayerNetID::FindPlayerByName(PlayerName, NULL);
        if(!pPlayer) {
            return;
        }
        /*ppos = eCoord(x,y);
        pdir = eCoord(dirx,diry);*/
	eCoord ppos, pdir;
	arena.LeastDangerousSpawnPoint()->Spawn( ppos, pdir );

        // let's respawn now ...
        eGameObject *pGameObject = pPlayer->Object();
        if ((!pGameObject) ||
            (!(pGameObject->Alive()) ))
        {
            gCycle *pCycle = new gCycle(grid, ppos, pdir, pPlayer);
            pPlayer->ControlObject(pCycle);
        }
}
static tConfItemFunc sg_RespawnPlayerRand_conf("RESPAWN_PLAYER_RANDOM",&sg_RespawnRand);
Image
Image
Image
User avatar
Tank Program
Forum & Project Admin, PhD
Posts: 6711
Joined: Thu Dec 18, 2003 7:03 pm

Post by Tank Program »

Sounds like something is happening when it gets around to destroying objects. Are you sure you're handling that properly?
Image
User avatar
ivantis
Round Winner
Posts: 269
Joined: Mon Mar 03, 2008 2:33 pm
Contact:

Post by ivantis »

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.
Image
Image
Image
User avatar
ivantis
Round Winner
Posts: 269
Joined: Mon Mar 03, 2008 2:33 pm
Contact:

Post by ivantis »

aha! maybe i need to add the line pPlayer->Object()->AddToList();? we'll find out, after the break.
Image
Image
Image
User avatar
ivantis
Round Winner
Posts: 269
Joined: Mon Mar 03, 2008 2:33 pm
Contact:

Post by ivantis »

nope, still seg fault. any other ideas?
Image
Image
Image
User avatar
ivantis
Round Winner
Posts: 269
Joined: Mon Mar 03, 2008 2:33 pm
Contact:

Post by ivantis »

maybe this will help: sometimes it says this instead of a seg fault:

Code: Select all

*** glibc detected *** /home/ivantis/0.2.8-armagetronad-sty+ct/bin/armagetronad-dedicated: free(): invalid pointer: 0x08335f00 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb7b95a85]
/lib/tls/i686/cmov/libc.so.6(cfree+0x90)[0xb7b994f0]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb7d60b11]
/home/ivantis/0.2.8-armagetronad-sty+ct/bin/armagetronad-dedicated[0x80db3e6]
/home/ivantis/0.2.8-armagetronad-sty+ct/bin/armagetronad-dedicated[0x80db50a]
/home/ivantis/0.2.8-armagetronad-sty+ct/bin/armagetronad-dedicated[0x8070328]
/home/ivantis/0.2.8-armagetronad-sty+ct/bin/armagetronad-dedicated[0x80722ad]
/home/ivantis/0.2.8-armagetronad-sty+ct/bin/armagetronad-dedicated[0x807e7e9]
/home/ivantis/0.2.8-armagetronad-sty+ct/bin/armagetronad-dedicated[0x807119c]
/home/ivantis/0.2.8-armagetronad-sty+ct/bin/armagetronad-dedicated[0x8071234]
/home/ivantis/0.2.8-armagetronad-sty+ct/bin/armagetronad-dedicated[0x80792b7]
/home/ivantis/0.2.8-armagetronad-sty+ct/bin/armagetronad-dedicated[0x807d508]
/home/ivantis/0.2.8-armagetronad-sty+ct/bin/armagetronad-dedicated[0x804ea79]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe0)[0xb7b40450]
/home/ivantis/0.2.8-armagetronad-sty+ct/bin/armagetronad-dedicated(__gxx_personality_v0+0x2e9)[0x804d181]
======= Memory map: ========
08048000-08215000 r-xp 00000000 08:01 893004     /home/ivantis/0.2.8-armagetronad-sty+ct/bin/armagetronad-dedicated
08215000-08216000 rw-p 001cd000 08:01 893004     /home/ivantis/0.2.8-armagetronad-sty+ct/bin/armagetronad-dedicated
08216000-0835c000 rw-p 08216000 00:00 0          [heap]
b6adf000-b6ae0000 ---p b6adf000 00:00 0 
b6ae0000-b72e0000 rw-p b6ae0000 00:00 0 
b72e0000-b72e1000 ---p b72e0000 00:00 0 
b72e1000-b7ae1000 rw-p b72e1000 00:00 0 
b7ae1000-b7ae3000 r-xp 00000000 08:01 1269854    /lib/libnss_mdns4.so.2
b7ae3000-b7ae4000 rw-p 00001000 08:01 1269854    /lib/libnss_mdns4.so.2
b7ae4000-b7af3000 r-xp 00000000 08:01 1287550    /lib/tls/i686/cmov/libresolv-2.7.so
b7af3000-b7af5000 rw-p 0000f000 08:01 1287550    /lib/tls/i686/cmov/libresolv-2.7.so
b7af5000-b7af7000 rw-p b7af5000 00:00 0 
b7af7000-b7afb000 r-xp 00000000 08:01 1287537    /lib/tls/i686/cmov/libnss_dns-2.7.so
b7afb000-b7afd000 rw-p 00003000 08:01 1287537    /lib/tls/i686/cmov/libnss_dns-2.7.so
b7b0e000-b7b10000 rw-p b7b0e000 00:00 0 
b7b10000-b7b24000 r-xp 00000000 08:01 2689157    /usr/lib/libz.so.1.2.3.3
b7b24000-b7b25000 rw-p 00013000 08:01 2689157    /usr/lib/libz.so.1.2.3.3
b7b25000-b7b27000 r-xp 00000000 08:01 1287528    /lib/tls/i686/cmov/libdl-2.7.so
b7b27000-b7b29000 rw-p 00001000 08:01 1287528    /lib/tls/i686/cmov/libdl-2.7.so
b7b29000-b7b2a000 rw-p b7b29000 00:00 0 
b7b2a000-b7c73000 r-xp 00000000 08:01 1287522    /lib/tls/i686/cmov/libc-2.7.so
b7c73000-b7c74000 r--p 00149000 08:01 1287522    /lib/tls/i686/cmov/libc-2.7.so
b7c74000-b7c76000 rw-p 0014a000 08:01 1287522    /lib/tls/i686/cmov/libc-2.7.so
b7c76000-b7c79000 rw-p b7c76000 00:00 0 
b7c79000-b7c83000 r-xp 00000000 08:01 1269824    /lib/libgcc_s.so.1
b7c83000-b7c84000 rw-p 0000a000 08:01 1269824    /lib/libgcc_s.so.1
b7c84000-b7ca7000 r-xp 00000000 08:01 1287530    /lib/tls/i686/cmov/libm-2.7.so
b7ca7000-b7ca9000 rw-p 00023000 08:01 1287530    /lib/tls/i686/cmov/libm-2.7.so
b7ca9000-b7d91000 r-xp 00000000 08:01 2689082    /usr/lib/libstdc++.so.6.0.9
b7d91000-b7d94000 r--p 000e8000 08:01 2689082    /usr/lib/libstdc++.so.6.0.9
b7d94000-b7d96000 rw-p 000eb000 08:01 2689082    /usr/lib/libstdc++.so.6.0.9
b7d96000-b7d9c000 rw-p b7d96000 00:00 0 
b7d9c000-b7da3000 r-xp 00000000 08:01 1287552    /lib/tls/i686/cmov/librt-2.7.so
b7da3000-b7da5000 rw-p 00006000 08:01 1287552    /lib/tls/i686/cmov/librt-2.7.so
b7da5000-b7df1000 r-xp 00000000 08:01 2761243    /usr/local/lib/libZThread-2.3.so.2.0.0
b7df1000-b7df3000 rw-p 0004c000 08:01 2761243    /usr/local/lib/libZThread-2.3.so.2.0.0
b7df3000-b7df4000 rw-p b7df3000 00:00 0 
b7df4000-b7f0d000 r-xp 00000000 08:01 2689151    /usr/lib/libxml2.so.2.6.31
b7f0d000-b7f12000 rw-p 00119000 08:01 2689151    /usr/lib/libxml2.so.2.6.31
b7f12000-b7f13000 rw-p b7f12000 00:00 0 
b7f13000-b7f27000 r-xp 00000000 08:01 1287548    /lib/tls/i686/cmov/libpthread-2.7.so
b7f2700Aborted
no idea what that means
Image
Image
Image
User avatar
Tank Program
Forum & Project Admin, PhD
Posts: 6711
Joined: Thu Dec 18, 2003 7:03 pm

Post by Tank Program »

ivantis wrote:maybe this will help: sometimes it says this instead of a seg fault:

Code: Select all

sty+ct/bin/armagetronad-dedicated: free(): invalid pointer: 0x08335f00 ***
A pointer isn't being set to NULL when it ought to be.
Image
User avatar
ivantis
Round Winner
Posts: 269
Joined: Mon Mar 03, 2008 2:33 pm
Contact:

Post by ivantis »

so one of the pointers needs to be NULL?
Image
Image
Image
User avatar
hoop
Round Winner
Posts: 201
Joined: Tue Jul 24, 2007 7:45 am
Contact:

Post by hoop »

Hi ivantis, I had a similar problem using
ePlayerNetID->Object()
ivantis wrote:

Code: Select all

        // 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.
User avatar
Z-Man
God & Project Admin
Posts: 11587
Joined: Sun Jan 23, 2005 6:01 pm
Location: Cologne
Contact:

Post by Z-Man »

hoop wrote:Hi ivantis, I had a similar problem using
ePlayerNetID->Object()
ivantis wrote:

Code: Select all

        // 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 #):

Code: Select all

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
Then, post the output here.
User avatar
hoop
Round Winner
Posts: 201
Joined: Tue Jul 24, 2007 7:45 am
Contact:

Post by hoop »

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:

Code: Select all

        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 ++;
        }
those crashes stopped once i changed it to:

Code: Select all

        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 ++;
            }
        }
User avatar
Z-Man
God & Project Admin
Posts: 11587
Joined: Sun Jan 23, 2005 6:01 pm
Location: Cologne
Contact:

Post by Z-Man »

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.
User avatar
hoop
Round Winner
Posts: 201
Joined: Tue Jul 24, 2007 7:45 am
Contact:

Post by hoop »

you refer to ePlayerNetID or to eGameObject check?
User avatar
Z-Man
God & Project Admin
Posts: 11587
Joined: Sun Jan 23, 2005 6:01 pm
Location: Cologne
Contact:

Post by Z-Man »

The e(Net)GameObject one. The ePlayerNetID one checks whether a player of that name was found.
User avatar
hoop
Round Winner
Posts: 201
Joined: Tue Jul 24, 2007 7:45 am
Contact:

Post by hoop »

Ok, I got the difference now :)
ivantis wrote:

Code: Select all

gArena arena = Arena;
[...]
arena.LeastDangerousSpawnPoint()->Spawn( ppos, pdir );
Why are you copying the Arena object in your function? You could (should?) just use the original one.
Perhaps is that causing the segmentation fault?
Post Reply