Array index out of bounds
#1

Hello, this is my code:
pawn Код:
public OnFilterScriptInit ()
{
    printf (" \nSchool Project Loaded.\n");

    SetTimer ("CheckValidTextDraws", 1000, 1);

    RadarHud = TextDrawCreate (495.0, 200.0, "~b~Model: ~n~~r~Speed:         kmph");
    TextDrawFont (RadarHud, 2);
    TextDrawLetterSize (RadarHud, 0.3, 1.0);

    for (new i = 1; i <= MAX_VEHICLES; i++)
    {
        VehRadarID [i] = -1;
        SpeedAndModel [i] = TextDrawCreate (545.0, 200.0, "~b~ ~n~~r~");
        TextDrawFont (SpeedAndModel [i], 2);
        TextDrawLetterSize (SpeedAndModel [i], 0.3, 1.0);
        CheckingSpeed [i] = 0;
    }

    return 1;
}
And that gives me something back from crashdetect:
Код:
[13:45:15] [debug] Run time error 4: "Array index out of bounds"
[13:45:15] [debug]  Accessing element at index 2000 past array upper bound 1999
[13:45:15] [debug] AMX backtrace:
[13:45:15] [debug] #0 000001f0 in public OnFilterScriptInit () from SchoolProject.amx
Why does it do that?
Reply
#2

Probably you have somewhere in your code something like
pawn Код:
new SpeedAndModel[2000]
//and/or
new VehRadarID[2000]
//and/or
new CheckingSpeed[2000]
You have 2 options:
pawn Код:
#NAME#[2000]
//changes into
#NAME#[2001]
or
pawn Код:
for (new i = 1; i <= MAX_VEHICLES; i++)
//changes into
for (new i = 0; i != MAX_VEHICLES; i++)
If you choose second option, you save one cell in each array, but you have to check your whole code and change all instances of this loop
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)