PDA

View Full Version : Run time error 4: "Array index out of bounds"


ajam123
08/07/2017, 06:43 AM
Please help wit this error

[06:17:30] [debug] Run time error 4: "Array index out of bounds"
[06:17:30] [debug] Attempted to read/write array element at index 255 in array of size 255
[06:17:30] [debug] AMX backtrace:
[06:17:30] [debug] #0 00082b7c in public OnVehicleSpawn (vehicleid=255) at #:\Hidden\Hidden\gamemodes\Hidden.pwn:11707
[06:17:30] [debug] #1 native SetVehicleToRespawn () from samp03svr
[06:17:30] [debug] #2 000c1e6c in LoadVehicle (i=255) at #:\Hidden\Hidden\gamemodes\Hidden.pwn:16345
[06:17:30] [debug] #3 000c0630 in LoadVehicles () at #:\Hidden\Hidden\gamemodes\Hidden.pwn:16292
[06:17:30] [debug] #4 00089544 in public zcmd_OnGameModeInit () at #:\Hidden\Hidden\gamemodes\Hidden.pwn:12246
[06:17:30] [debug] #5 native CallLocalFunction () from samp03svr
[06:17:30] [debug] #6 00009e0c in public IRC_OnGameModeInit () at #:\Hidden\Hidden\pawno\include\zcmd.inc:51
[06:17:30] [debug] #7 native CallLocalFunction () from samp03svr
[06:17:30] [debug] #8 000098b8 in public OnGameModeInit () at #:\Hidden\Hidden\pawno\include\irc.inc:200
[06:17:30] [debug] Run time error 4: "Array index out of bounds"
[06:17:30] [debug] Attempted to read/write array element at index 256 in array of size 255


public OnVehicleSpawn(vehicleid)
{
if(vehicleid>sizeof(Vehicles)) return DestroyVehicle(vehicleid);
vTrailer[vehicleid] = 0;
CarBombActive[vehicleid] = 0;
vehicleGuns[vehicleid] = 0;
vehicleBullets[vehicleid] = 0;
for(new i=0;i<13;i++)
{
VehicleWeapon[vehicleid][i] = 0;
VehicleAmmo[vehicleid][i] = 0;
}
HasGunCrates[vehicleid] = 0;
HasBulletCrates[vehicleid] = 0;
comps[vehicleid][guns] = 0;
comps[vehicleid][oil] = 0;
comps[vehicleid][alchool] = 0;
comps[vehicleid][money] = 0;
comps[vehicleid][drugs] = 0;
comps[vehicleid][stuffs] = 0;
compscar[vehicleid] = 0; //line 11707
}

Tass007
08/07/2017, 06:50 AM
How have you defined the variable "Vehicles"?

Do you have any other code in your script using the variable Vehicles? Or just anything around vehicles generally?

ajam123
08/07/2017, 06:54 AM
I have variables for vehicles and yes.

Kane
08/07/2017, 07:14 AM
Show lines 11707, 16345, 16292 and 12246.

FailerZ
08/07/2017, 07:16 AM
I guess this happens when the loop reach to a number and that number is not in the array

ajam123
08/07/2017, 07:21 AM
Show lines 11707, 16345, 16292 and 12246.


11707 = compscar[vehicleid] = 0;
16345 = SetVehicleToRespawn(i);
16292 = LoadVehicle(i);
12246 = SendRconCommand("mapname Los Santos");

ajam123
08/07/2017, 05:36 PM
BUMP! Anyone?

Vince
08/07/2017, 06:06 PM
Replace
if(vehicleid>sizeof(Vehicles))
with
if(vehicleid >= sizeof(Vehicles))
If you have an array size 255 then sizeof will return 255 BUT the highest index you can access is 254.