[SOLVED] [debug] Run time error 4: "Array index out of bounds" - PutuSuhartawan - 2021-05-17
SOLUTION bye Y_Less:
Code: // A newbie scripter can replace sysmbol from??`>` instead of `>=` to check the slot upper-bounds.
//Newbie also use a define for the upper bound, which is good, then hard-coded the value in the string, which defeats the object.
// sample fix:
if(slot >= MAX_TRUNK_SLOTS || slot <= 0) return SCM(playerid, -1, "VEHICLE: Max trunk slot is 3 sir.",1);
// befor and error will be lauch if:
if(slot > MAX_TRUNK_SLOTS || slot <?0) return SCM(playerid, -1, "VEHICLE: Max trunk slot is 3 sir.",1);
Code: DEBUG: Adding item trunk in slot:[4]
[debug] Run time error 4: "Array index out of bounds"
[debug]? Attempted to read/write array element at index 4 in array of size 4
[debug] AMX backtrace:
[debug] #0 0011df1c in public cmd_addoctrunkitem (0, 43242908) in SuhartawanWorld.amx
[debug] #1 native CallLocalFunction () in samp-server.exe
[debug] #2 0001b36c in public FIXES_OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx
[debug] #3 00006270 in public OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx
SELECT * FROM `trunkdata` ORDER BY oc_id ASC, slot ASC - <Query change in [40] Mili Second>
DEBUG: Adding item trunk in slot:[3]
DEBUG: Slot filter hassben passed sir
[debug] Run time error 4: "Array index out of bounds"
[debug]? Attempted to read/write array element at index 4 in array of size 4
[debug] AMX backtrace:
[debug] #0 0011e128 in public cmd_addoctrunkitem (0, 43242908) in SuhartawanWorld.amx
[debug] #1 native CallLocalFunction () in samp-server.exe
[debug] #2 0001b36c in public FIXES_OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx
[debug] #3 00006270 in public OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx
SELECT * FROM `trunkdata` ORDER BY oc_id ASC, slot ASC - <Query change in [5] Mili Second>
DEBUG: Adding item trunk in slot:[2]
DEBUG: Slot filter hassben passed sir
[debug] Run time error 4: "Array index out of bounds"
[debug]? Attempted to read/write array element at index 4 in array of size 4
[debug] AMX backtrace:
[debug] #0 0011e128 in public cmd_addoctrunkitem (0, 43242908) in SuhartawanWorld.amx
[debug] #1 native CallLocalFunction () in samp-server.exe
[debug] #2 0001b36c in public FIXES_OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx
[debug] #3 00006270 in public OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx
SELECT * FROM `trunkdata` ORDER BY oc_id ASC, slot ASC - <Query change in [2] Mili Second>
DEBUG: Adding item trunk in slot:[1]
DEBUG: Slot filter hassben passed sir
[debug] Run time error 4: "Array index out of bounds"
[debug]? Attempted to read/write array element at index 4 in array of size 4
[debug] AMX backtrace:
[debug] #0 0011e128 in public cmd_addoctrunkitem (0, 43242908) in SuhartawanWorld.amx
[debug] #1 native CallLocalFunction () in samp-server.exe
[debug] #2 0001b36c in public FIXES_OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx
[debug] #3 00006270 in public OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx
Pawn script:
Code: CMD:addoctrunkitem(playerid, params[])
{
//LoadOCTrunks();
new result = n_mysql_query(g_Sql, "SELECT * FROM `trunkdata` ORDER BY oc_id ASC, slot ASC", true);
new rows = cache_num_rows();
new str[500], NewSQL_ID;
? ? new targetOC_ID, slot, item_type, amount, value;
? ? if(sscanf(params, "iiiii", targetOC_ID, slot, item_type, amount, value)) return SCM(playerid, -1, "USAGE: /addoctrunkitem [targetOC_ID]? [slot] [item_type] [amount] [value]");
? ? new playa,carid=GetRealIdCar(targetOC_ID);
? ? if(slot > MAX_VEHICLE_TRUNK_SLOTS || slot < 0) return SCM(playerid, -1, "VEHICLE: Max trunk slot is 4 sir.",1);
? ? printf("DEBUG: Adding item trunk in slot:[%d]", slot);
? ? if(get_vehicle_trunk[carid][slot][TRUNK_SLOT]==slot) return SCM(playerid, -1, "OC_TRUNK: That slot has been used in this vehicle sir. Please remove item from this slot first.",1);
? ? /*
? ? ? for(new s=1; s<=10; s)
? ? {
? ? ? ? if(get_vehicle_trunk[carid][s][TRUNK_SQL_ID]>0)continue;
? ? ? ? if(get_vehicle_trunk[carid][s][TRUNK_SQL_ID]==slot)
? ? ? ? {
? ? ? ? break;
? ? ? ? }
? ? }
? */
? ? if(!IsValidVehicle(carid))return SCM(playerid, -1, "VEHICLE: Thats vehicle has not exist sir.",1);
? printf("DEBUG: Slot filter hassben passed sir");
? ? new VID = targetOC_ID;
? ? for(new v; v<=50; v)
? ? {
? ? for(new slot; slot<=5; slot)
? ? {
? ? for(new idx; idx < rows; idx )
? ? ? ? ? ? {
? ? cache_get_value_int(idx, "id", get_vehicle_trunk[v][slot][TRUNK_SQL_ID] );
? ? ? ? if(get_vehicle_trunk[v][slot][TRUNK_SQL_ID]>0)continue;
? ? ? ? if(get_vehicle_trunk[v][slot][TRUNK_SQL_ID]==0)
? ? ? ? {
? ? ? ? ? ? NewSQL_ID = get_vehicle_trunk[v][slot][TRUNK_SQL_ID]; break; // find emty slot vehicle ID. with find number primary car player
? ? ? ? }
? ? }
? ? }
? ? }
? ? cache_delete(result);
? ? slot, get_vehicle_trunk[carid][slot][TRUNK_ITEM_TYPE] = item_type, get_vehicle_trunk[carid][slot][TRUNK_ITEM_AMOUNT] = amount, get_vehicle_trunk[carid][slot][TRUNK_ITEM_VALUE] = value;
?
? ? format(str, sizeof(str), "INSERT INTO `trunkdata` (`id`, `owner_id`, `oc_id`, `slot`, `item_type`, `amount`, `value`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d')", NewSQL_ID, pInfo[playerid][ID], VID, slot, item_type, amount, value);
n_mysql_query(g_Sql, str);
SCM(playerid,-1,"VEHICLE: You have adding item at this trunk vehicle",2);
SendClientMessage(playerid,-1, str);
return true;
}
RE: HELP! [debug] Run time error 4: "Array index out of bounds" - Y_Less - 2021-05-17
You used `>` instead of `>=` to check the slot upper-bounds.
You also use a define for the upper bound, which is good, then hard-coded the value in the string, which defeats the object.
RE: HELP! [debug] Run time error 4: "Array index out of bounds" - PutuSuhartawan - 2021-05-17
(2021-05-17, 08:51 AM)Y_Less Wrote: You used `>` instead of `>=` to check the slot upper-bounds.
You also use a define for the upper bound, which is good, then hard-coded the value in the string, which defeats the object.
The error notifcation steal running sir
Code: [TRUNK_DEBUG]: Loaded trunk have:[0 row(s)]
[debug] Run time error 4: "Array index out of bounds"
[debug]? Attempted to read/write array element at index 4 in array of size 4
[debug] AMX backtrace:
[debug] #0 00052014 in ?? () in SuhartawanWorld.amx
[debug] #1 000fd494 in public GEOLITE_OnGameModeInit () in SuhartawanWorld.amx
[debug] #2 0004ed58 in public T3DV4_OnGameModeInit () in SuhartawanWorld.amx
[debug] #3 0004ca6c in public Indirection_OnGameModeInit () in SuhartawanWorld.amx
[debug] #4 0002b860 in public ScriptInit_OnGameModeInit () in SuhartawanWorld.amx
[debug] #5 0001d968 in public GZ_OnGameModeInit () in SuhartawanWorld.amx
[debug] #6 0001b454 in ?? () in SuhartawanWorld.amx
[debug] #7 native CallLocalFunction () in samp-server.exe
[debug] #8 0001aff8 in public SSCANF_OnGameModeInit () in SuhartawanWorld.amx
[debug] #9 0000d004 in public FIXES_OnGameModeInit () in SuhartawanWorld.amx
[debug] #10 000037c4 in public OnPlayerLeaveDynamicArea () in SuhartawanWorld.amx
[debug] Run time error 20: "Invalid index parameter (bad entry point)"
Script[gamemodes/SuhartawanWorld.amx]: Run time error 20: "Invalid index parameter (bad entry point)"
Pawn script:
Code: stock LoadOCTrunks()
{
? ? ? ? ?
? ? ? ? ? new Cache: result, rows;
? ? ? ? ? new vehicleid, VID, slot, buffer;
? ? ? ? ? result = mysql_query(g_Sql, "SELECT * FROM `trunkdata` ORDER BY oc_id ASC, slot ASC", true);
? ? ? ? ? rows = cache_num_rows();
? ? ? ? ? printf("[TRUNK_DEBUG]: Loaded trunk have:[%d row(s)]", rows);
? ? ? ? ? //VID = GetOwnableCarBySqlID( cache_get_value_int(idx, "oc_id", GetOwnableCarData(vehicleid, OC_SQL_ID) ));
? ? ? ? ? //v=GetRealIdCar(VID);
? ? ? ? ? for(new v; v <= MAX_VEHICLES; v )
? ? ? ? ? {
? ? ? ? ? ? ? for(new s; s <= MAX_VEHICLE_TRUNK_SLOTS; s )
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? for(new idx; idx <= rows; idx )
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? cache_get_value_int(idx, "slot", get_vehicle_trunk[v][s][TRUNK_SLOT] );
? ? ? ? ? ? ? ? ? ? ? ? ? slot = get_vehicle_trunk[v][s][TRUNK_SLOT];
? ? ? ? ? ? ? ? ? ? ? ? ? if(slot != 0)
? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if(get_vehicle_trunk[v][s][TRUNK_SLOT] == slot)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? printf("[TRUNK_DEBUG]: Slot loaded in ID:[%d]", slot);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if(v != INVALID_VEHICLE_ID)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //if(GetTrunkData(v, slot, TRUNK_SQL_ID)) continue;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cache_get_value_int(idx, "id", get_vehicle_trunk[v][slot][TRUNK_SQL_ID] );
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? printf("[TRUNK_DEBUG]: Data trunk was? downloaded from SQL ID:[%d]", get_vehicle_trunk[v][slot][TRUNK_SQL_ID]);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cache_get_value_int(idx, "item_type", get_vehicle_trunk[v][slot][TRUNK_ITEM_TYPE] );
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cache_get_value_int(idx, "amount", get_vehicle_trunk[v][slot][TRUNK_ITEM_AMOUNT] );
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? cache_get_value_int(idx, "value", get_vehicle_trunk[v][slot][TRUNK_ITEM_VALUE] );
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? buffer ;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }?
? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? }
? ? ? ? ? }
? ? ? ? ? ? ?
? ? ? ? ? cache_delete(result);
? ? ? ? ? printf("[Trunks]: Item on upload from SQL: %d", buffer);
}
RE: HELP! [debug] Run time error 4: "Array index out of bounds" - Pinch - 2021-05-17
Add
Code: if (!rows) return 1;
Before the first for loop
Also, loop through rows, not MAX_VEHICLES
RE: HELP! [debug] Run time error 4: "Array index out of bounds" - PutuSuhartawan - 2021-05-17
(2021-05-17, 09:13 AM)Pinch Wrote: Add
Code: if (!rows) return 1;
Before the first for loop
Also, loop through rows, not MAX_VEHICLES
How to change the MAX_VEHICLES sir? why not need it?
steal error sir:
Code: [OwnableCars]: Spawned: [4 vehicle(s)]
[TRUNK_DEBUG]: Loaded trunk have:[4 row(s)]
[TRUNK_DEBUG]: Slot loaded in ID:[5]
[debug] Run time error 4: "Array index out of bounds"
[debug]? Attempted to read/write array element at index 5 in array of size 4
[debug] AMX backtrace:
[debug] #0 00052204 in ?? () in SuhartawanWorld.amx
[debug] #1 000fd4c4 in public GEOLITE_OnGameModeInit () in SuhartawanWorld.amx
[debug] #2 0004ed58 in public T3DV4_OnGameModeInit () in SuhartawanWorld.amx
[debug] #3 0004ca6c in public Indirection_OnGameModeInit () in SuhartawanWorld.amx
[debug] #4 0002b860 in public ScriptInit_OnGameModeInit () in SuhartawanWorld.amx
[debug] #5 0001d968 in public GZ_OnGameModeInit () in SuhartawanWorld.amx
[debug] #6 0001b454 in ?? () in SuhartawanWorld.amx
[debug] #7 native CallLocalFunction () in samp-server.exe
[debug] #8 0001aff8 in public SSCANF_OnGameModeInit () in SuhartawanWorld.amx
[debug] #9 0000d004 in public FIXES_OnGameModeInit () in SuhartawanWorld.amx
[debug] #10 000037c4 in public OnPlayerLeaveDynamicArea () in SuhartawanWorld.amx
[debug] Run time error 20: "Invalid index parameter (bad entry point)"
Script[gamemodes/SuhartawanWorld.amx]: Run time error 20: "Invalid index parameter (bad entry point)"
is from invalid array enum?
Code: enum VEHICLE_TRUNK_STRUCTUR
{
? TRUNK_SQL_ID,
? TRUNK_SLOT,
? TRUNK_OC_ID,
? TRUNK_OWNER_ID,
? TRUNK_ITEM_TYPE,? ? // Name of item
? TRUNK_ITEM_AMOUNT,? // value
? TRUNK_ITEM_VALUE? ? // weigh Kg
};
new get_vehicle_trunk[MAX_VEHICLES][MAX_VEHICLE_TRUNK_SLOTS][VEHICLE_TRUNK_STRUCTUR];
|