SA-MP Forums Archive
Array index out of bounds problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Array index out of bounds problem (/showthread.php?tid=488663)



Array index out of bounds problem - thimo - 18.01.2014

Hello, i have a problem with getting array index out of bounds ONLY when there are 100 or more rows in the mysql table.
This is the code:
pawn Код:
forward OnBansLoad();
public OnBansLoad()
{
    new
        rows,
        fields
    ;
    cache_get_data( rows, fields, Handle);

    if(!rows)
    {
        print("Bans table is empty, no results found.");
        return 1;
    }
    new
        i = 0
    ;
    while(rows > i)
    {
        APlayerData[i][BanVariable] = true;// You had only this, no loading any other

        printf("Ban %d Loaded", i);
        i++;
    }
    return 1;
}
Why is it giving me that weird thing. Its not even when compiling, it shows up when loading the server via crashdetect.


Re: Array index out of bounds problem - Patrick - 18.01.2014

The problem could be the APlayerData[i][BanVariable], Can you show me how you declare this enum or 2D Array.


Re: Array index out of bounds problem - InglewoodRoleplay - 18.01.2014

The problem relies here:

pawn Код:
while(rows > i)
    {
        APlayerData[i][BanVariable] = true;// You had only this, no loading any other

        printf("Ban %d Loaded", i);
        i++;
    }

//while(i < rows) would make more sense though, at least for me. It would be easier to understand.
Increment the size on the array for APlayerData
The max size for [i] has to be incremented where you defined the array.


Re: Array index out of bounds problem - thimo - 19.01.2014

pawn Код:
enum pEnum
{
    Name[MAX_PLAYER_NAME],
    Text3D:NameTag[31],
    Password[31],
    Admin,
    Money,
    Score,
    Points,
    PlayerLogged,
    CourierHouses[11],
    CourierMaxStep,
    Float:X,
    Float:Y,
    Float:Z,
    Float:Rot,
    bool:AText,
    bool:PlayerVariable[MAX_PLAYERS],
    bool:BanVariable,
    ECoins,
    Muted,
    LastPmID,
    pAccent[128],
    TruckerLicense,
    Windows,
    SpectateID,
    SpectateType,
    EngineStarted,
    Text:Location,
    CurrentHouse,
    Houses[MAX_HOUSESPERPLAYER],
    SpectateVehicle,
    gEngine,
    MLevel,
    DonatorLevel,
    PlayerClass,
    JobStep,
    bool:AFK,
    bool:JobStarted,
    JobLoc1,
    JobLoc2,
    LoadID,
    VehicleID,
    TrailerID,
    VehicleTimerTime,
    JobID,
    VehicleTimer,
    LoadingTimer,
    StatsTruckerJobs,
    StatsPilotJobs,
    StatsPlayersFined,
    StatsConvoyJobs,
    Fines[MAX_PLAYERS],
    PlayerSpeed,
    PlayerCaughtSpeeding,
    PlayerCheckTimer,
    PlayerJailed,
    PlayerJailedTimer,
    bool:PoliceWarnedMe,
    Value_PoliceCanJailMe,
    Timer_PoliceCanJailMe,
    bool:PoliceCanJailMe,
    Warnings,
    DialogGetCarHouseID,
    bool:InConvoy,
    ConvoyID,
    StatsCourierJobs
}



Re: Array index out of bounds problem - Patrick - 19.01.2014

Your code will give Array index out of bounds because you are loading more than 500 bans, so MAX_PLAYERS is equals to 500 so you exceeded the max value, that is why you're getting the crashdetect warning, and why do you want to declare the enum'ed array as true?

pawn Код:
APlayerData[i][BanVariable] = true;//why Do you need in loading rows? because this is a per-player enum,



Re: Array index out of bounds problem - thimo - 19.01.2014

When you delete a row in mysql it sets it as false. So the ID slot can be used again. Also the BanVariable doesnt have [MAX_PLAYERS] behind it?


Re: Array index out of bounds problem - Patrick - 19.01.2014

Quote:
Originally Posted by thimo
Посмотреть сообщение
When you delete a row in mysql it sets it as false. So the ID slot can be used again. Also the BanVariable doesnt have [MAX_PLAYERS] behind it?
What does it have then? because you placed it inside a per-player enumerated array, maybe that is why Array Index out of bounds occurs.


Re: Array index out of bounds problem - thimo - 19.01.2014

Im a retard. Sorry i got it fixed now