Run time error 4: "Array index out of bounds"
#1

I have the following code:

pawn Код:
forward OnFCar_Load();
public OnFCar_Load(){
    if(!cache_num_rows()) return printf("There are no faction cars to load.");

    new rows, fields, vehicleid;
    cache_get_data(rows, fields, sqlConnection);
   
    for(new i = 0; i != cache_get_row_count(); i++)
    {  
        vehicleid = CreateVehicle(FactionCars[i][fCarModel], FactionCars[i][fCarPos][1], FactionCars[i][fCarPos][2], FactionCars[i][fCarPos][3], FactionCars[i][fCarPos][4], FactionCars[i][fCarColor][1], FactionCars[i][fCarColor][2], -1);
   
        FactionCars[vehicleid][fCarID] = cache_get_field_content_int(i, "ID", sqlConnection);
        FactionCars[vehicleid][fCarModel] = cache_get_field_content_int(i, "Model", sqlConnection);
        FactionCars[vehicleid][fCarLocked] = cache_get_field_content_int(i, "Locked", sqlConnection);
        FactionCars[vehicleid][fCarFaction] = cache_get_field_content_int(i, "Faction", sqlConnection);
        FactionCars[vehicleid][fCarInterior] = cache_get_field_content_int(i, "Interior", sqlConnection);
        FactionCars[vehicleid][fCarWorld] = cache_get_field_content_int(i, "World", sqlConnection);
       
        FactionCars[vehicleid][fCarColor][1] = cache_get_field_content_int(i, "C1", sqlConnection);
        FactionCars[vehicleid][fCarColor][2] = cache_get_field_content_int(i, "C2", sqlConnection);
       
        FactionCars[vehicleid][fCarPos][1] = cache_get_field_content_float(i, "X", sqlConnection);
        FactionCars[vehicleid][fCarPos][2] = cache_get_field_content_float(i, "Y", sqlConnection);
        FactionCars[vehicleid][fCarPos][3] = cache_get_field_content_float(i, "Z", sqlConnection);
        FactionCars[vehicleid][fCarPos][4] = cache_get_field_content_float(i, "A", sqlConnection);
       
        LinkVehicleToInterior(vehicleid, FactionCars[vehicleid][fCarInterior]);
        SetVehicleVirtualWorld(vehicleid, FactionCars[vehicleid][fCarWorld]);
       
        new engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid, engine, lights, alarm, FactionCars[vehicleid][fCarLocked], bonnet, boot, objective);
       
        countFCars ++;
    }

    printf("%d faction cars loaded from the database.", countFCars);
    return 1;
}
When it's called, it shows the following:

Код:
[13:42:10] R: 0 F: 0
[13:42:10] [debug] Run time error 4: "Array index out of bounds"
[13:42:10] [debug]  Accessing element at index 65535 past array upper bound 499
[13:42:10] [debug] AMX backtrace:
[13:42:10] [debug] #0 0001db48 in public OnFCar_Load () from gm.amx
This is the database:



It's not loading anything, just showing that error.
Reply
#2

Which is the 65535th line?
Reply
#3

It's nothing to do with the line, it's not a PAWNO error but a crashdetect error. There's something in that callback which is causing an error but I don't know what.
Reply
#4

Try getting the value of cache_get_row_count() using printf
Reply
#5

The result of

pawn Код:
printf("cache_get_row_count() = %d", cache_get_row_count());
Shows

Код:
cache_get_row_count() = 1
Reply
#6

Somewhere, the code is trying to access the 65535th element of an array. 65535=INVALID_PLAYER_ID
Like this:
pawn Код:
new artay[MAX_PLAYERS];
printf("%d", array[INVALID_PLAYER_ID];
It can be a function returning INVALID_PLAYER_ID
Reply
#7

The whole code doesn't have anything in regards to players at all. It's loading vehicles from a database.
Reply
#8

INVALID_VEHICLE_ID is 65535, So check for the vehicle id by printing the 'vehicleid' variable to console.
Reply
#9

pawn Код:
new vehicleid = CreateVehicle(FactionCars[i][fCarModel], FactionCars[i][fCarPos][1], FactionCars[i][fCarPos][2], FactionCars[i][fCarPos][3], FactionCars[i][fCarPos][4], FactionCars[i][fCarColor][1], FactionCars[i][fCarColor][2], -1);
   
        printf("vehicleid = %d", vehicleid);

Doing that, prints: vehicleid = 65535

So, it's something regarding that.
Reply
#10

The logic seems a bit off..

First you are creating a vehicle from existing data (not from the database) only to get an ID.. and then use the id to set the data in the array. Is this what you actually want?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)