[debug] Run time error 4: "Array index out of bounds"
#1

Hi guys! Can somebody help me to detect the problem from this script? REP++

PHP код:
[17:15:13] [debugRun time error 4"Array index out of bounds"
[17:15:13] [debug]   Accessing element at index 65535 past array upper bound 99
[17:15:13] [debugAMX backtrace:
[
17:15:13] [debug#0  00018a0c in public OnPlayerDeath () from GM.amx 
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    // (Update Kills/Deaths)
    AccInfo[playerid][Deaths]++;
    userid = BUD::GetNameUID( PlayerName2(playerid) );
    BUD::MultiSet( userid, "i", "Deaths", AccInfo[playerid][Deaths]);
    AccInfo[killerid][Kills]++;
    userid = BUD::GetNameUID( PlayerName2(killerid) );
    BUD::MultiSet( userid, "i", "Kills", AccInfo[killerid][Kills]);
    // (Clan Kills/Deaths)
    if( IsPlayerAnyClanMember(playerid) && IsPlayerAnyClanMember(killerid) )
    {
    new clanquery[300];
    format(clanquery, sizeof(clanquery), "UPDATE clans SET clankills = %d WHERE clanname = '%s'", GetClanKills(GetPlayerClan(killerid)) + 1, GetPlayerClan(killerid));
    db_query( Database, clanquery );
    format(clanquery, sizeof(clanquery), "UPDATE clans SET clandeaths = %d WHERE clanname = '%s'", GetClanDeaths(GetPlayerClan(playerid)) + 1, GetPlayerClan(playerid));
    db_query( Database, clanquery );
    }
    // (Snow)
    if(Snow_F[playerid] == 1){Snow_F[playerid] = 0;}
    // (Race)
    if(Joined[playerid] == true)
    {
        JoinCount--;
        Joined[playerid] = false;
        DestroyVehicle(CreatedRaceVeh[playerid]);
        DisablePlayerRaceCheckpoint(playerid);
        TextDrawHideForPlayer(playerid, Text:RaceInfo[playerid]);
        CPProgess[playerid] = 0;
        KillTimer(InfoTimer[playerid]);
        #if defined RACE_IN_OTHER_WORLD
        SetPlayerVirtualWorld(playerid, 0);
        #endif
    }
    SendDeathMessage(killerid,playerid,reason);//Msg
    if(gPlayerUsingLoopingAnim[playerid])
    {
        gPlayerUsingLoopingAnim[playerid] = 0;
        TextDrawHideForPlayer(playerid,txtAnimHelper);
    }
    // (End)
    InDuel[playerid] = 0;
    // (LuxAdmin)
    if(AccInfo[playerid][pCaged] == 1)
    {
    cage[playerid]  = DestroyObject(cage[playerid]);
    cage2[playerid] = DestroyObject(cage2[playerid]);
    cage3[playerid] = DestroyObject(cage3[playerid]);
    cage4[playerid] = DestroyObject(cage4[playerid]);
    }
    if(IsPlayerConnected(killerid) && killerid != INVALID_PLAYER_ID)
    {
    //==============================================================================
    // In Duel
    //==============================================================================
        if(InDuel[playerid] == 1 && InDuel[killerid] == 1)
        {
        GameTextForPlayer(playerid,"Loser!",3000,3);
        GameTextForPlayer(killerid,"Winner!",3000,3);
        InDuel[killerid] = 0;
        SetPlayerPos(killerid, 0.0, 0.0, 0.0);
        SpawnPlayer(killerid);
        }
        else if(InDuel[playerid] == 1 && InDuel[killerid] == 0)
        {
        GameTextForPlayer(playerid,"Loser !",3000,3);
        }
    }
    //==============================================================================
    // Spectate
    //==============================================================================
    for(new xp=0; xp<MAX_PLAYERS; xp++)
    if(GetPlayerState(xp) == PLAYER_STATE_SPECTATING && AccInfo[xp][SpecID] == playerid)
    AdvanceSpectate(xp);
    // (Mega Mode)
    DeletePVar(playerid, "Status");
    DestroyObject(GetPVarInt(playerid, "mode0"));
    DestroyObject(GetPVarInt(playerid, "mode1"));
    DestroyObject(GetPVarInt(playerid, "mode2"));
    DestroyObject(GetPVarInt(playerid, "mode3"));
    DestroyObject(GetPVarInt(playerid, "mode4"));
    DestroyObject(GetPVarInt(playerid, "mode5"));
    DeletePVar(playerid, "BStatus");
    DestroyObject(GetPVarInt(playerid, "bmode0"));
    DestroyObject(GetPVarInt(playerid, "bmode1"));
    DestroyObject(GetPVarInt(playerid, "bmode2"));
    DestroyObject(GetPVarInt(playerid, "bmode3"));
    return ( 1 );
}
Reply
#2

You have to check if killerid is INVALID_PLAYER_ID before you use it on an array as an index.

INVALID_PLAYER_ID equals 65536 (0xFFFF).

This is what your really doing if killerid is invalid. (example)
pawn Код:
new array[ MAX_PLAYERS ];

array[ 65536 ] = something;//indexed oob
For example OnPlayerDeath should be similar to:
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if( killerid != INVALID_PLAYER_ID )
    {
        ++kills[ killerid ];//killerid is ok it's not INVALID_PLAYER_ID
        ++deaths[ playerid ];
    }
    else
    {
        //dont use killerid as index here it's INVALID_PLAYER_ID
        ++deaths[ playerid ];
    }
    return 1;
}
Reply
#3

thx where can i learn this things?
Reply
#4

So I changed the house number to 90 from 131.. and I deleted a few vehicles from my PHP. still not working.
(I only deleted them from my PHP gamemode not modified)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)