[Crash Detect Errors] Array bounds..
#1

001[05:16:13] [debug] Run time error 4: "Array index out of bounds"
[05:16:13] [debug] Accessing element at index 50 past array upper bound 49
[05:16:13] [debug] AMX backtrace:
[05:16:13] [debug] #0 0007da64 in public TimeConn () from script.amx

code :

pawn Код:
public TimeConn()
{
    for(new i=0;i<=MAX_PLAYERS;i++)
    {
        if(PLAYERLIST_authed[i] && IsPlayerConnected(i))
        {
            if (PlayerInfo[i][bail]!=777)
            {
                PlayerInfo[i][playertime]= dUserINT(PlayerName(i)).("time");
                PlayerInfo[i][playertime] +=200;
                dUserSetINT(PlayerName(i)).("time",PlayerInfo[i][playertime]);
            }
  }
        PlayerTemp[i][ishealing] = 0;
    }
    return 1;
}
Reply
#2

Solution: Change the <= to < in the loop.

Explanation:
Say MAX_PLAYERS is 10, player IDs range from 0 to 9, and <= means less than or equal to, meaning it will call it for ID 10, even though ID 10 can't exist. If you have this array:

pawn Код:
new someArray[MAX_PLAYERS];
Calling someArray[10] will cause an OOB error, as the max index is 9 (don't forget things start at 0).
Reply
#3

MP2 , thank you very much. I'm new to this crash detect plugin. You helped me alot
Reply
#4

Another question same issue.

Code :
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{

    Kicked[playerid] = false;

    KillTimer(CPTimer[playerid]); KillTimer(SpawnTimer[playerid]);
//    ResetPlayerPropertyInfo(playerid, reason);
    KillTimer(PlayerTemp[playerid][DropTimer]);
    KillTimer(PlayerTemp[playerid][RobTimer]);
    KillTimer(PlayerTemp[playerid][RobBizTimer]);
    KillTimer(PlayerTemp[playerid][lictimer]);
    new Float:pposX, Float:pposY, Float:pposZ;
    GetPlayerPos(playerid, pposX, pposY, pposZ);
    dUserSet(PlayerName(playerid)).("lastonline",TimeDate());
    for(new x=0; x<MAX_PLAYERS; x++)
    {
        if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && gSpectateID[x] == playerid) AdvanceSpectate(x);
    }
    new playername[MAX_PLAYER_NAME];
    new str[MAX_STRING];
//  if(namesenable == 1 && NickCheck(playerid,0)) return 1;
    switch (reason)
    {
        case 0:
        {
Errors :
[05:17:06] [debug] Run time error 4: "Array index out of bounds"
[05:17:06] [debug] Accessing element at index 255 past array upper bound 99
[05:17:06] [debug] AMX backtrace:
[05:17:06] [debug] #0 00068a08 in public Streamer_OnPlayerDisconnect () from script.amx
[05:17:06] [debug] #1 0000e1e8 in ?? () from bluegamesv1.amx
[05:17:06] [debug] #2 00000e58 in public OnPlayerDisconnect () from script.amx

As you can see there is no <= there, only < - Thank in advance.
Reply
#5

Could you post the AdvanceSpectate function? You may also want to make sure that gSpectateID has MAX_PLAYERS cells.
Reply
#6

Edited OnPlayerDeath -

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    if(PlayerInfo[killerid][jail] || PlayerInfo[playerid][jail]) return 1;
    if(gPlayerUsingLoopingAnim[playerid])
    {
        gPlayerUsingLoopingAnim[playerid] = 0;
        TextDrawHideForPlayer(playerid,txtAnimHelper);
    }
    File::SaveAccount(playerid);
    if(reason == 38 && GetAdminLevel(killerid) && !IsPlayerInAnyVehicle(killerid) && !PlayerTemp[killerid][isevent])
    {
        new Float:pP[4];
        GetPlayerPos(playerid,pP[0], pP[1], pP[2]);
        SetTimerEx("SetPlayerPosExEx", 2000, false, "dfffddd", playerid, pP[0], pP[1], pP[2], GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid), INVALID_VEHICLE_ID);
        return 1;
    }
    if(killerid != INVALID_PLAYER_ID && killerid != 54 && killerid != 255)
    {
        if(PlayerTemp[playerid][onpaint])
        {
            PlayerLoop(i)
            {
                if(!PlayerTemp[i][onpaint]) continue;
                SendClientMSG(i, COLOR_YELLOW, " [PB]: %s has killed %s with a %s (Distance: %dm)", RPName(killerid), RPName(playerid), aWeaponNames[reason], GetDistanceBetweenPlayers(playerid, killerid));
                OnPlayerKillSpree(killerid);
            }
            return 1;
        }
        if(PlayerTemp[killerid][isevent])
        {
            PlayerLoop(i)
            {
                if(!PlayerTemp[i][isevent]) continue;
                SendClientMSG(i, COLOR_YELLOW, "[EVENT]: %s has killed %s with a %s (Distance: %dm).", RPName(killerid), RPName(playerid), aWeaponNames[reason], GetDistanceBetweenPlayers(playerid, killerid));
                OnPlayerKillSpree(killerid);
            }
            PlayerTemp[playerid][isevent] = 0;
            return 1;
        }
        if(PlayerTemp[playerid][deaded]==0 && killerid != INVALID_PLAYER_ID){
        new wname[ 40 ],string[200];
        new Float:px, Float:py, Float:pz;
        GetPlayerPos(playerid,px,py,pz);
        GetWeaponName(reason, wname, sizeof(wname));
        format( string, sizeof(string), "5[DEATH] %s[%d] has been killed by %s[%d] (%s).",PlayerName(playerid),playerid, PlayerName(killerid), killerid,wname);
        iEcho( string );
        PlayerTemp[playerid][deathINT]=GetPlayerInterior(playerid);
        PlayerTemp[playerid][deathX]=px;
        PlayerTemp[playerid][deathY]=py;
        PlayerTemp[playerid][deathZ]=pz;
        PlayerTemp[playerid][deathVW]=GetPlayerVirtualWorld(playerid);
        PlayerTemp[playerid][deaded] = 1;
        PlayerTemp[playerid][killedby]=killerid;
        PlayerTemp[playerid][weaponome]=reason;
        EzeeCubeH[playerid] = SetTimerEx("EzeeCubeHeal",500,0,"ii",playerid,1);
        return 1;
        }
        PlayerTemp[playerid][weaponome]=-1;
        PlayerTemp[playerid][killedby]=INVALID_PLAYER_ID;
        if(killerid != INVALID_PLAYER_ID && PlayerInfo[killerid][playerteam] != EMS) SendDeathMessage(killerid,playerid,reason);
        {
            CheckWar();
            new winpoints;
            {
                switch(PlayerInfo[playerid][ranklvl])
                {
                    case 0: winpoints = 10;
                    case 1: winpoints = 5;
                    case 2: winpoints = 2;
                    default: winpoints = 1;
                }
            }
            if(PlayerInfo[killerid][playerteam] == dini_Int(warfile,"faction1") && PlayerInfo[playerid][playerteam] == dini_Int(warfile,"faction2"))
            {
                dini_IntSet(warfile, "faction1points", dini_Int(warfile,"faction1points") + winpoints);
            }
            else if(PlayerInfo[killerid][playerteam] == dini_Int(warfile,"faction2") && PlayerInfo[playerid][playerteam] == dini_Int(warfile,"faction1"))
            {
                dini_IntSet(warfile, "faction2points", dini_Int(warfile,"faction2points") + winpoints);
            }
        }
        //SetPlayerWantedLevel(playerid, 0);
        TextDrawHideForPlayer(playerid, PlayerTemp[playerid][Status]);
        TextDrawHideForPlayer(playerid, TextDraw__News);
        TextDrawHideForPlayer(playerid, IMtxt);
        new
        string[ MAX_STRING ], wname[ 40 ], ragione[ 40 ];
        GetWeaponName(reason, wname, sizeof(wname));
        format( string, sizeof(string), "[DEATH] %s[%d] has been killed by %s[%d] (%s).",PlayerName(playerid),playerid, PlayerName(killerid), killerid,wname);
        iEcho( string );
        format( string, sizeof(string), "[KILL] %s has killed %s with a %s", PlayerName(killerid), PlayerName(playerid), wname);
        AppendTo(deathlog, string);
        GetWeaponName(reason,ragione,40);
        if(PlayerInfo[killerid][playerteam] == CIV)SendClientMessageToAll(COLOR_RED, string);

        if(IsPlayerDriver(killerid) && PlayerInfo[killerid][playerteam]!=SASF && PlayerInfo[killerid][playerteam]!=FBI && PlayerInfo[killerid][playerteam]!=COPS && PlayerInfo[killerid][power]==0)
        {
            PlayerTemp[killerid][imprisoned] = 1;
            Jail(killerid,600,777,"Drive-by");
            format(iStr,sizeof(iStr),"{FFFFFF}[ {FF0000}ADMIN{FFFFFF} ] {FF6347}* SERVER has jailed %s for 10 minutes. Reason: Drive-by *",RPName(killerid));
            SendMessageToAll(COLOR_RED,iStr);
        }
        if(killerid != INVALID_PLAYER_ID && IsPlayerInPaintball(killerid))
        {
            if(PlayerTemp[playerid][pbteam] == 1) PBTeams[PlayerTemp[playerid][onpaint]][redscore]++;
            else PBTeams[PlayerTemp[playerid][onpaint]][bluescore]++;
            UpdatePBScore(PlayerTemp[playerid][onpaint], PBTeams[PlayerTemp[playerid][onpaint]][redscore], PBTeams[PlayerTemp[playerid][onpaint]][bluescore]);
            return 1;
        }
        if(killerid != INVALID_PLAYER_ID) PlayerInfo[killerid][kills]++;
        PlayerInfo[playerid][deaths]++;
        if(!strlen(ragione)) ragione="Fists";
        new deathmsg[MAX_STRING]; format(deathmsg,sizeof(deathmsg),"Info: You have paid $%d for the medical bills, have a nice day!",dini_Int(globalstats, "medicals"));
        SendClientMessage(playerid,COLOR_ORANGE,deathmsg);
        if(killerid != INVALID_PLAYER_ID && PlayerInfo[killerid][playerteam]==EMS && PlayerInfo[playerid][head]>0)
        {
            if(strcmp(ragione,"Knife",true)==0)
            {
                new total;
                total=PlayerInfo[playerid][head]+((PlayerInfo[playerid][head]*15)/100);
                dini_IntSet(globalstats,"EMSBank",dini_Int(globalstats,"EMSBank")+total/2);
                GivePlayerMoneyEx(killerid, total/2);
                format(string,sizeof(string),"[HEAD] You earned $%d from %s head, plus 15-percent of his head because of knifekill.",PlayerInfo[playerid][head]/2,PlayerName(playerid));
                SendClientMessage(killerid,COLOR_YELLOW, string);
                PlayerInfo[playerid][head]=0;
            }
            else
            {
                GivePlayerMoneyEx(killerid, PlayerInfo[playerid][head]/2);
                dini_IntSet(globalstats,"EMSBank",dini_Int(globalstats,"EMSBank")+PlayerInfo[playerid][head]/2);
                format(string,sizeof(string),"[HEAD] You earned $%d from %s head.",PlayerInfo[playerid][head]/2,PlayerName(playerid));
                SendClientMessage(killerid,COLOR_YELLOW, string);
                PlayerInfo[playerid][head]=0;
            }
        }
    }
    else
    {
        if(PlayerInfo[playerid][power])
        {
            PlayerLoop(i)
            {
                SendDeathMessage(killerid, playerid, reason);
            }
            return 1;
        }
        new string[ 128 ];
        format(string,sizeof(string), "Suicide: %s has suicided", RPName(playerid));
        if(GetPVarInt(playerid, "SkinSelect") == 0) SendClientMessageToAll(COLOR_RED, string);
        format( string, sizeof(string), "[DEATH] %s[%d] has suicided.",PlayerName(playerid),playerid);
        iEcho( string );
        format( string, sizeof(string), "[KILL] %s has killed himself", PlayerName(playerid));
        AppendTo(deathlog, string);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)