Array index out of bounds problem
#1

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.
Reply
#2

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

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.
Reply
#4

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
}
Reply
#5

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,
Reply
#6

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?
Reply
#7

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.
Reply
#8

Im a retard. Sorry i got it fixed now
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)