1

Topic: [Modding] Segfault on Team change

So far I've only changed the mod.h and mod.cpp files and I have a problem with the following code:

int CGameControllerMOD::OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon)
{
    pVictim->GetPlayer()->SetTeam(TEAM_SPECTATORS, true);
    IGameController::OnCharacterDeath(pVictim,pKiller,Weapon);
    return 0;
}

Now, when someone dies the client gives a "too weak connection (out of buffer)" error message and the server repeats

[56eb3b0b][server]: client dropped. cid=0 addr=unknown type 0 reason='Error sending data'
[56eb3b0b][chat]: *** 'Ace' joined the spectators
[56eb3b0b][server]: client dropped. cid=0 addr=unknown type 0 reason='Error sending data'
[56eb3b0b][chat]: *** 'Ace' joined the spectators

Over and over until there is a segmentation fault.
It's the first line of the function, without it it runs fine.
The same error occurs when I put the line after 
IGameController::OnCharacterDeath(pVictim,pKiller,Weapon);
so I don't think I change the address of the character in SetTeam(), do I?

2 (edited by TT <3 2016-03-18 01:43:17)

Re: [Modding] Segfault on Team change

I think after changing the team of the victim, the character of the player already died and zero'ed, thus you're accessing invalid memory (meaning you cant use "pVictim" anymore).
Use a debugger to check further details and why it fails.

3

Re: [Modding] Segfault on Team change

Thanks for the response; I was thinking the same, but I didn't see anything in SetTeam() that would actually do that. I guess I'll just look up how zCatch handles it tomorrow.

4

Re: [Modding] Segfault on Team change

SetTeam(..) calls KillCharacter(...). KillCharacter(..) removes the character so the character is gone. It makes sense... the character is only there if the player is alive and the player is not alive if it is spectating.

Simply swapping the 2 lines should solve your problem.

uptee - a simple web interface for hosting and maintaining teeworlds servers
teerace - a website gathering results of trusted Race-mod servers providing global ranking and statistics
*gV* rox ^^