[crashdetect] "Array index out of bounds" [rep +++]
#1

I using crashdetect plugin on my server, and some player drives car I got this:
Код:
[18:01:20] [debug] AMX backtrace:
[18:01:20] [debug] #0 00048e64 in ?? () from PPCT.amx
[18:01:20] [debug] #1 00048594 in public Speedometer_Update () from PPCT.amx
[18:01:20] [debug] Run time error 4: "Array index out of bounds"
[18:01:20] [debug]  Accessing element at index 200 past array upper bound 199
I using PPC_Trucking gamemode. Speedometer_Update is timer, here's code:

pawn Код:
// This function gets called by a timer which runs every 500ms to display and update the speedometer
public Speedometer_Update(playerid)
{
    // Setup local variables
    new vehicleid, Float:speed_x, Float:speed_y, Float:speed_z, Float:final_speed, speed_string[512], final_speed_int, Float:vehiclehealth;
    new FuelString[64], FuelStatus[64];
    new Msg[256], Name[24];

    // Get the ID of the player's vehicle
    vehicleid = GetPlayerVehicleID(playerid);

    //******************************************************************************************************************************
    // Anti-hack stuff
    //******************************************************************************************************************************

    AntiHack(playerid);

    //******************************************************************************************************************************
    // End of anti-hack stuff
    //******************************************************************************************************************************

    // Check and toggle spectate-mode when needed (when target player entered or exited his vehicle)
    if (GetPlayerState(playerid) == PLAYER_STATE_SPECTATING)
    {
        // Get the target player's ID and name
        new OtherPlayer = APlayerData[playerid][SpectateID];
        GetPlayerName(OtherPlayer, Name, sizeof(Name));

        // Use the same worldid and interiorid as the OtherPlayer
        SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(OtherPlayer));
        SetPlayerInterior(playerid, GetPlayerInterior(OtherPlayer));

        // Check if the player is spectating a player
        if (APlayerData[playerid][SpectateType] == ADMIN_SPEC_TYPE_PLAYER)
        {
            // Check if the target player has entered a vehicle
            if (GetPlayerVehicleSeat(OtherPlayer) != -1)
            {
                // Change spectate mode to vehicle
                PlayerSpectateVehicle(playerid, GetPlayerVehicleID(OtherPlayer));
                APlayerData[playerid][SpectateID] = OtherPlayer;
                APlayerData[playerid][SpectateVehicle] = GetPlayerVehicleID(OtherPlayer);
                APlayerData[playerid][SpectateType] = ADMIN_SPEC_TYPE_VEHICLE;
                format(Msg, 256, "{00FF00}Igrac {FFFF00}%s{00FF00} je usao u vozilo. Mijenjam nacin nadziranja igraca.", Name);
                SendClientMessage(playerid, 0xFFFFFFFF, Msg);
            }
        }
        else // The player is spectating a vehicle
        {
            // Check if the target player has exited a vehicle
            if (GetPlayerVehicleSeat(OtherPlayer) == -1)
            {
                // Change spectate mode to player
                PlayerSpectatePlayer(playerid, OtherPlayer);
                SetPlayerInterior(playerid, GetPlayerInterior(OtherPlayer));
                APlayerData[playerid][SpectateID] = OtherPlayer;
                APlayerData[playerid][SpectateType] = ADMIN_SPEC_TYPE_PLAYER;
                format(Msg, 256, "{00FF00}Igrac {FFFF00}%s{00FF00} je izasao iz vozila. Mijenjam nacin nadziranja igraca.", Name);
                SendClientMessage(playerid, 0xFFFFFFFF, Msg);
            }
        }
    }

    // When the player got a wanted level and a police player warned him to stop, a timer is started and a variable is set to "true"
    // Check if this variable has been set
    if (APlayerData[playerid][PoliceWarnedMe] == true)
    {
        // Check if the player has no wanted level anymore (after finishing a overloaded mission, player got fined, ...)
        if (APlayerData[playerid][KolikoTrazen] == 0)
        {
            APlayerData[playerid][PoliceCanJailMe] = false; // Clear the variable
            APlayerData[playerid][PoliceWarnedMe] = false; // Clear the variable
            APlayerData[playerid][Value_PoliceCanJailMe] = 0; // Clear the remaining time for the timer
            KillTimer(APlayerData[playerid][Timer_PoliceCanJailMe]); // Kill the timer
        }
    }

    // If the player is inside a vehicle
    if(vehicleid != 0)
    {
        // Get the vehicles velocity
        GetVehicleVelocity(vehicleid, speed_x, speed_y, speed_z);
        // Calculate the speed (in kph)
        final_speed = floatsqroot(((speed_x * speed_x) + (speed_y * speed_y)) + (speed_z * speed_z)) * 158.179;
        // Convert the float value to an int value
        final_speed_int = floatround(final_speed, floatround_round);
        // Also save the speed for the player
        APlayerData[playerid][PlayerSpeed] = final_speed_int;
        // Setup the string to display for the player and display it
        if(final_speed_int < 20){
            format(speed_string, 512, TXT_SpeedometerSpeed1, final_speed_int);
            TextDrawShowForPlayer(playerid, PlayerData[playerid][Brzina1]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina2]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina3]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina4]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina5]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina6]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina7]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina8]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina9]);
        }
        if(final_speed_int > 20){
            format(speed_string, 512, TXT_SpeedometerSpeed1, final_speed_int);
            TextDrawShowForPlayer(playerid, PlayerData[playerid][Brzina1]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina2]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina3]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina4]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina5]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina6]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina7]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina8]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina9]);
        }
        if(final_speed_int > 40){
            format(speed_string, 512, TXT_SpeedometerSpeed1, final_speed_int);
            TextDrawShowForPlayer(playerid, PlayerData[playerid][Brzina2]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina3]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina4]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina5]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina6]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina7]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina8]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina9]);
        }
        if(final_speed_int > 60){
            format(speed_string, 512, TXT_SpeedometerSpeed2, final_speed_int);
            TextDrawShowForPlayer(playerid, PlayerData[playerid][Brzina3]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina4]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina5]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina6]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina7]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina8]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina9]);
        }
        if(final_speed_int > 80){
            format(speed_string, 512, TXT_SpeedometerSpeed2, final_speed_int);
            TextDrawShowForPlayer(playerid, PlayerData[playerid][Brzina4]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina5]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina6]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina7]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina8]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina9]);
        }
        if(final_speed_int > 100){
            format(speed_string, 512, TXT_SpeedometerSpeed2, final_speed_int);
            TextDrawShowForPlayer(playerid, PlayerData[playerid][Brzina5]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina6]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina7]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina8]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina9]);
        }
        if(final_speed_int > 120){
            format(speed_string, 512, TXT_SpeedometerSpeed3, final_speed_int);
            TextDrawShowForPlayer(playerid, PlayerData[playerid][Brzina6]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina7]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina8]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina9]);
        }
        if(final_speed_int > 140){
            format(speed_string, 512, TXT_SpeedometerSpeed3, final_speed_int);
            TextDrawShowForPlayer(playerid, PlayerData[playerid][Brzina7]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina8]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina9]);
        }
        if(final_speed_int > 160){
            format(speed_string, 512, TXT_SpeedometerSpeed3, final_speed_int);
            TextDrawShowForPlayer(playerid, PlayerData[playerid][Brzina8]);
            TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina9]);
        }
        if(final_speed_int > 180){
            format(speed_string, 512, TXT_SpeedometerSpeed3, final_speed_int);
            TextDrawShowForPlayer(playerid, PlayerData[playerid][Brzina9]);
        }
//      if(final_speed_int > 60){
    //      format(speed_string, 512, TXT_SpeedometerSpeed2, final_speed_int);
        //}
        //if(final_speed_int > 120){
        //  format(speed_string, 512, TXT_SpeedometerSpeed3, final_speed_int);
        //}

        TextDrawSetString(PlayerData[playerid][SpeedometerText], speed_string);

        // Add the speed to the stats (this will be the meters driven in total)
        APlayerData[playerid][StatsMetersDriven] = APlayerData[playerid][StatsMetersDriven] + (final_speed / 7.2);

        // Also display the vehicle's health through the player-health bar
        GetVehicleHealth(vehicleid, vehiclehealth);


        new Linija[128], VoziloTD[128];
        format(Linija, sizeof(Linija), "Zdravlje: ~r~%i", floatround(vehiclehealth) / 10);
        TextDrawSetString(PlayerData[playerid][vHealth], Linija);
       
       
   
       
        if(GetPVarInt(playerid, "tempomat_status") == 0){
            TextDrawSetString(PlayerData[playerid][TDTempomat], "Tempomat: iskljucen");
        }
        else if(GetPVarInt(playerid, "tempomat_status") == 1){
            TextDrawSetString(PlayerData[playerid][TDTempomat], "Tempomat: ukljucen");
        }
       
        format(VoziloTD, 128, "Vozilo: %s", VehicleNames2[GetVehicleModel(GetPlayerVehicleID(playerid))-400]);
        TextDrawSetString(PlayerData[playerid][Vozilo], VoziloTD);


        // Check if the speed is above 10kph and the fuel of the vehicle isn't empty yet
        if ((final_speed_int > 10) && (AVehicleData[vehicleid][Fuel] > 0))
            AVehicleData[vehicleid][Fuel] = AVehicleData[vehicleid][Fuel] - 1; // Decrease the fuel for this vehicle every time the timer is run

        // Construct the fuelgauge
        if ((AVehicleData[vehicleid][Fuel] > 0) && (AVehicleData[vehicleid][Fuel] < 100000))
            format(FuelStatus, 64, "~g~%s~r~%s", "I", "........."); // Fuel is between 0% and 10% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 1)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 2)))
            format(FuelStatus, 64, "~g~%s~r~%s", "II", "........"); // Fuel is between 10% and 64% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 2)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 3)))
            format(FuelStatus, 64, "~g~%s~r~%s", "III", "......."); // Fuel is between 64% and 30% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 3)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 4)))
            format(FuelStatus, 64, "~g~%s~r~%s", "IIII", "......"); // Fuel is between 30% and 40% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 4)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 5)))
            format(FuelStatus, 64, "~g~%s~r~%s", "IIIII", "....."); // Fuel is between 40% and 50% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 5)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 6)))
            format(FuelStatus, 64, "~g~%s~r~%s", "IIIIII", "...."); // Fuel is between 50% and 60% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 6)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 7)))
            format(FuelStatus, 64, "~g~%s~r~%s", "IIIIIII", "..."); // Fuel is between 60% and 70% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 7)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 8)))
            format(FuelStatus, 64, "~g~%s~r~%s", "IIIIIIII", ".."); // Fuel is between 70% and 80% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 8)) && (AVehicleData[vehicleid][Fuel] < ((MaxFuel / 10) * 9)))
            format(FuelStatus, 64, "~g~%s~r~%s", "IIIIIIIII", "."); // Fuel is between 80% and 90% full

        if ((AVehicleData[vehicleid][Fuel] >= ((MaxFuel / 10) * 9)) && (AVehicleData[vehicleid][Fuel] <= MaxFuel))
            format(FuelStatus, 64, "~g~%s", "IIIIIIIIII"); // Fuel is between 90% and 100% full (all bars are green)

        if (AVehicleData[vehicleid][Fuel] == 0)
            format(FuelStatus, 64, "~r~%s", "Nema Goriva"); // Fuel is empty (all bars are red)

        // Format the final fuel-gauge readout
        format(FuelString, 64, TXT_SpeedometerFuel, FuelStatus);
        // Display the fuel-gauge
        TextDrawSetString(PlayerData[playerid][FuelGauge], FuelString);

        // Check if the vehicle is out of fuel
        if (AVehicleData[vehicleid][Fuel] == 0)
        {
            // Stop the engine and turn off the lights
            new engine,lights,alarm,doors,bonnet,boot,objective;
            GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(vehicleid, 0, 0, alarm, doors, bonnet, boot, objective);
        }

        // Check if the player is not in any plane or helicopter (those cannot be caught by speedcamera's)
        if (IsVehicleAirVehicle(vehicleid) == 0)
            if (APlayerData[playerid][PlayerClass] != ClassPolice) // Check if the player isn't speeding (cops won't get caught)
                if (APlayerData[playerid][PlayerClass] != ClassMilitary)
                    CheckPlayerSpeeding(playerid);
    }
    else
    {
        // If the player is not inside a vehicle, display an empty string (looks like the speedometer is gone)
        TextDrawSetString(PlayerData[playerid][SpeedometerText], " ");
        TextDrawSetString(PlayerData[playerid][FuelGauge], " ");
        TextDrawSetString(PlayerData[playerid][vHealth], " ");
        TextDrawSetString(PlayerData[playerid][Vozilo], " ");
        TextDrawSetString(PlayerData[playerid][TDTempomat], "  ");
       
        TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina1]);
        TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina2]);
        TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina3]);
        TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina4]);
        TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina5]);
        TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina6]);
        TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina7]);
        TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina8]);
        TextDrawHideForPlayer(playerid, PlayerData[playerid][Brzina9]);
       

        // Set the speed of the player to 0
        APlayerData[playerid][PlayerSpeed] = 0;
    }
}
Can anyone resolve this? Coz after some time players can't see speedometer and other TextDraws.

Definition for textdraws:
Код:
enum TPlayerDataNew
{
	Text:MissionText[MAX_PLAYERS],
	Text:Cmds[MAX_PLAYERS],
	Text:Box[MAX_PLAYERS],
	Text:SpeedometerText[MAX_PLAYERS],
	Text:FuelGauge[MAX_PLAYERS], 
	Text:vHealth[MAX_PLAYERS],
	Text:Vozilo[MAX_PLAYERS],
	Text:TDTempomat[MAX_PLAYERS],
	Text:Brzina1[MAX_PLAYERS],
	Text:Brzina2[MAX_PLAYERS],
	Text:Brzina3[MAX_PLAYERS],
	Text:Brzina4[MAX_PLAYERS],
	Text:Brzina5[MAX_PLAYERS],
	Text:Brzina6[MAX_PLAYERS],
	Text:Brzina7[MAX_PLAYERS],
	Text:Brzina8[MAX_PLAYERS],
	Text:Brzina9[MAX_PLAYERS],
	Text:Brzina10[MAX_PLAYERS],
}

new PlayerData[MAX_PLAYERS][TPlayerDataNew];
Reply
#2

Anyone?
Reply
#3

Debug it. An example would be:
pawn Код:
// Get the target player's ID and name
new OtherPlayer = APlayerData[playerid][SpectateID];
printf("OtherPlayer = %d", OtherPlayer); // DEBUG message
GetPlayerName(OtherPlayer, Name, sizeof(Name));
Reply
#4

It give me warning/error for every player that is in car...
Reply
#5

Do you show the name of the vehicle? If so, you need to check if the modelid is between 400 and 611. Else it will crash your server.

In Speedometer_Update:

pawn Код:
new
    modelid = GetVehicleModel( GetPlayerVehicleID( playerid ) )
;
if( modelid >= 400 && modelid <= 611 )
{
    // rest of the code;
    // show the name of the vehicle
}
Reply
#6

Fixed, but still Warning... :/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)