Lots of runtime errors/index out of bounds.
#1

Lately I've been noticing that my server sometimes crashes when a player spawns / disconnects, so I got the crashdetect plugin and noticed that I got lots of run time errors, I fixed some, but I have no idea how to fix the others ones.

OnPlayerDisconnect;
[02:17:00] [debug] Run time error 4: "Array index out of bounds"
[02:17:00] [debug] Accessing element at index 5 past array upper bound 4
[02:17:00] [debug] AMX backtrace:
[02:17:00] [debug] #0 0003b078 in public Itter_OnPlayerDisconnect (playerid=0, reason=1) at C:\Users\PC\Desktop\Pawn\gamemodes\HydraDogFight.p wn:2421
[02:17:00] [debug] #1 00007908 in public SSCANF_OnPlayerDisconnect (playerid=0, reason=1) at C:\Users\PC\Desktop\Pawn\pawno\include\YSI\y_itera te.inc:909
[02:17:00] [debug] #2 000008d0 in public OnPlayerDisconnect (playerid=0, reason=1) at C:\Users\PC\Desktop\Pawn\pawno\include\sscanf2.inc :229

OnPlayerSpawn;
[02:17:37] [debug] Run time error 4: "Array index out of bounds"
[02:17:37] [debug] Accessing element at index 5 past array upper bound 4
[02:17:37] [debug] AMX backtrace:
[02:17:37] [debug] #0 0003c050 in public OnPlayerSpawn (playerid=0) at C:\Users\PC\Desktop\Pawn\gamemodes\HydraDogFight.p wn:2494

pawn Код:
public OnPlayerSpawn(playerid)
{
    if(!PlayerInfo[playerid][IsJailed])
    {
        if(SpawnType[playerid] == SPAWNMODE_DEFAULT)
        {
            new
                Float:x, Float:y, Float:z, bool:found;
            if(gTeam[playerid] == TEAM_USA)
            {
                for(new i = 1; i < MAX_VEHICLES; i++)
                {
                    if(HydraInUse{ i } || IsVehicleOccupied(i)) continue;
                    else if(i > 23) break;

                    GetVehiclePos(i, x, y, z), found = true;
                    break;
                }
                SetPlayerColor(playerid, COLOR_USA);
            }
            else if(gTeam[playerid] == TEAM_RUSSIA)
            {
                for(new i = 24; i < MAX_VEHICLES; i++)
                {
                    if(HydraInUse{ i } || IsVehicleOccupied(i)) continue;
                    else if(i >= 45) break;

                    GetVehiclePos(i, x, y, z), found = true;
                    break;
                }
                SetPlayerColor(playerid, COLOR_RUSSIA);
            }
            SetPlayerInterior(playerid, 0), SetPlayerVirtualWorld(playerid, 0);
            GivePlayerWeaponEx(playerid, 24, 1500);
            GivePlayerWeaponEx(playerid, WEAPON_SHOTGSPA, 1500);
            GivePlayerWeaponEx(playerid, WEAPON_M4, 1500), GivePlayerWeaponEx(playerid, WEAPON_SNIPER, 100);
            GivePlayerWeaponEx(playerid, WEAPON_GRENADE, 3), GivePlayerWeaponEx(playerid, WEAPON_ROCKETLAUNCHER, 1);
            SetPlayerHealth(playerid, 99), SetPlayerArmour(playerid, 99);
            if(found) SetPlayerPos(playerid, x, y, z+4);
            else
            {
                if(gTeam[playerid] == TEAM_USA) SetPlayerPos(playerid, 279.4629, 2030.1803, 18.2025);
                else if(gTeam[playerid] == TEAM_RUSSIA) SetPlayerPos(playerid, -1257.1313, 203.0132, 15.0607);
            }
        }
        else if(SpawnType[playerid] == SPAWNMODE_STUNT)
        {
            SetPlayerSkin(playerid, 3);
            SetPlayerVirtualWorld(playerid, 155), ResetPlayerWeapons(playerid), SetPlayerPos(playerid, -1296.5253,4.3884,14.1484);
            SetPlayerColor(playerid, COLOR_GRAY);
            gTeam[playerid] = NO_TEAM;
            SetPlayerTeam(playerid, gTeam[playerid]);
            SetPlayerHealth(playerid, 999999);
            SetPlayerArmour(playerid, 999999);
        }
        FixTeams(), FixSelections();
    }
    else
    {
        SetPlayerInterior(playerid, 10);
        new rnd = random(sizeof(JailSpawnPoints));
        SetPlayerPos(playerid, JailSpawnPoints[rnd][0], JailSpawnPoints[rnd][1], JailSpawnPoints[rnd][2]);
        SetPlayerFacingAngle(playerid, JailSpawnPoints[rnd][3]);
        SetPlayerColor(playerid, COLOR_GREY);

        JailTimer[playerid] = SetTimerEx("JailT", 60000, false, "i", playerid), TimeInJail[playerid] = 60000;
        SendClientMessage(playerid, COLOR_NOTES2, "JAIL: You will be released in 60 seconds");
    }
    dueling{ playerid } = false, DuelInfo[playerid][targetid] = INVALID_PLAYER_ID, DuelInfo[playerid][HydraDuel] = false;
    TextDrawHideForPlayer(playerid, VehicleInfo[playerid]), TextDrawHideForPlayer(playerid, VehicleBox[playerid]);
    CapturingZone[playerid] = ZONE_NONE, InZone[playerid] = ZONE_NONE, PlayerHydra[playerid] = INVALID_VEHICLE_ID, IsSpectating{ playerid } = false, SpectatingTarget[playerid] = INVALID_PLAYER_ID;
    TextDrawHideForPlayer(playerid, SpectateInfo[playerid]);
    for(new line=0; line < 6; line++) TextDrawShowForPlayer(playerid, BoxMsg[line]); //2494
    return 1;
}
Reply
#2

It seems that one array is causing the problem in both callbacks
Go through both of ur callbacks and note the arrays common in them
Then see if common arrays are declared properly or not[their array size]...

If this doesn't work then after each line do print("LINE NO HERE");
Then execute the script and you will know exact line of error
Reply
#3

Quote:
Originally Posted by BroZeus
Посмотреть сообщение
It seems that one array is causing the problem in both callbacks
Go through both of ur callbacks and note the arrays common in them
Then see if common arrays are declared properly or not[their array size]...

If this doesn't work then after each line do print("LINE NO HERE");
Then execute the script and you will know exact line of error
Actually, I just needed to change
for(new line=0; line < 6; line++) TextDrawShowForPlayer(playerid, BoxMsg[line]);
to
for(new line=0; line < 5; line++) TextDrawShowForPlayer(playerid, BoxMsg[line]);

And everything got fixed o.o
Reply
#4

Use sizeof to prevent this in the future and to make it easier for yourself. sizeof is an operator, not a function. It has no impact on performance.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)