Array index out of bounds - 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 (
/showthread.php?tid=457375)
Array index out of bounds -
thimo - 11.08.2013
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?
Re: Array index out of bounds -
Misiur - 11.08.2013
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