Spectate functions problems
#1

My spectate functions are causing troubles for me, i really dont know why so i ask here.
Here is the affected functions:

pawn Код:
stock StartSpectate(playerid, specid)
{
    foreach(Player, x)
    {
        if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && gSpectateID[x] == playerid) AdvanceSpectate(x);
    }
    SetPlayerInterior(playerid,GetPlayerInterior(specid));
    SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(specid));
    TogglePlayerSpectating(playerid, 1);
    if(IsPlayerInAnyVehicle(specid))
    {
        PlayerSpectateVehicle(playerid, GetPlayerVehicleID(specid));
        gSpectateID[playerid] = specid;
        gSpectateType[playerid] = ADMIN_SPEC_TYPE_VEHICLE;
    }
    else
    {
        PlayerSpectatePlayer(playerid, specid);
        gSpectateID[playerid] = specid;
        gSpectateType[playerid] = ADMIN_SPEC_TYPE_PLAYER;
    }
    new string[40];
    if(PVar[playerid][pLevel] >0)
    {
        format(string,sizeof(string),"~n~~n~~n~~n~~n~~n~~n~~n~~w~%s - ID:%d~n~< Sprint - Jump >", pName(specid), specid);
        GameTextForPlayer(playerid,string,9999999,3);
    }
    return 1;
}
pawn Код:
stock AdvanceSpectate(playerid)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && gSpectateID[playerid] != INVALID_PLAYER_ID)
    {
        for(new x=gSpectateID[playerid]+1; x<=MAX_PLAYERS; x++)
        {
            if(x == MAX_PLAYERS) x = 0;
            if(IsPlayerConnected(x) && x != playerid)
            {
                if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && gSpectateID[x] != INVALID_PLAYER_ID || (GetPlayerState(x) != 1 && GetPlayerState(x) != 2 && GetPlayerState(x) != 3))
                {
                    continue;
                }
                else
                {
                    StartSpectate(playerid, x); // Line 15736
                    break;
                }
            }
        }
    }
    return 1;
}
OnPlayerKeyStateChange:
pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && gSpectateID[playerid] != INVALID_PLAYER_ID)
    {
        if(newkeys == KEY_JUMP)
            AdvanceSpectate(playerid); // Line 13919
        else if(newkeys == KEY_SPRINT)
            ReverseSpectate(playerid);
    }
At first i wanted to make theese functions with y_iterate, but lack of time made me take theese from luxadmin.
After 1 day or more of uptime, crashdetect plugin goes crazy and gives me this:

pawn Код:
[14:58:01]:   File 'D:\Documents and Settings\***/Skrivebord\Dev\gamemodes\MySQL_v6.0.0.1.pwn', line 13919
[14:58:01]:     AdvanceSpectate(playerid=12)
[14:58:01]:   File 'D:\Documents and Settings\***\Skrivebord\Dev\gamemodes\MySQL_v6.0.0.1.pwn'
[14:58:01]:     public OnPlayerKeyStateChange(playerid=12, newkeys=9, oldkeys=9)
[14:58:01]: Script[gamemodes/MySQL_v6.0.0.1.amx]: In file 'D:\Documents and Settings\***\Skrivebord\Dev\gamemodes\MySQL_v6.0.0.1.pwn' at line 15628:
[14:58:01]: Script[gamemodes/MySQL_v6.0.0.1.amx]: Run time error 3: "Stack/heap collision (insufficient stack size)"
[14:58:01]: Additional information:
[14:58:01]:   Stack index (STK) is 0x396784, heap index (HEA) is 0x396748
[14:58:01]: Call stack (most recent call first):
[14:58:02]:   File 'D:\Documents and Settings\***\Skrivebord\Dev\gamemodes\MySQL_v6.0.0.1.pwn', line 15736
[14:58:02]:     StartSpectate(playerid=12, specid=9)
This causes big problem to the server since the crashdetect file grows insanely HUGE. Every single error is with theese functions and they are written 100's of times to crashdetect log every second this problem occur.
Is there anything to do besides completely disable this?

Thanks in advance to those who are able to help me find a solution to this.
Reply
#2

bump, its been 2 days and !response :/
Reply
#3

Bumping it one last time :/
Reply
#4

Try debugging it. Could be that you're trying to access an invalid array index.

pawn Код:
new var = 10;
new array[5];
array[var] = 0; // Crash
See https://sampwiki.blast.hk/wiki/Debugging
Reply
#5

I can send you the proper information later on but right now I'm in the school
Reply
#6

Thanks for response guys. The problem is, the server ran problemfree for 2 days straight, then theese debug messages suddenly came. The spectate functions are used everytime OnPlayerSpawn is called after they die.
Reply
#7

I don't know if it has anything to do with it, but string[40] is obviously too small to handle what you're formatting into it. Also, why is it created in the outer scope when you don't use it there?

I think using the -d3 compilation flag will eventually lead to problems like this being pointed out. With no debugging, you wouldn't probably notice and the message would just be cut off?
Reply
#8

Never had any prob with the string. Name (24) makesroom for like 15 more char. Besides that thing is only shown to admins. (pLevel == admin). And i think im already compiling with -d3 or possivly -d2. I can check it later today since im not at home now.

Edit: after counting the letters i see i should increase the string size. I have prolly been lucky with shorter names since i havent noticed problem. Thanks for bringing it to my attention. Ill check if thats whats causing it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)