Array index out of bounds
#1

I saw the error in serverlog , but really don't know why its happens
PHP код:
14:44:35] [debugRun time error 4"Array index out of bounds"
[14:44:35] [debug]  Attempted to read/write array element at index 65535 in array of size 2000
[14:44:35] [debugAMX backtrace:
[
14:44:35] [debug#0 00031bb4 in House_AddVehicle (HouseID=3, cModel=0, cPaint=256, cComponents[]=@00405cbc "", Float:cx=283.04770, Float:cy=-1168.74146, Float:cz=80.46407, Float:crot=290.78180, Col1=16, Col2=16) at E:\V1-1.1.1\pawno\include\PPC_Housing.inc:237
[14:44:35] [debug#1 00033030 in House_ReplaceVehicle (HouseID=3, CarSlot=3) at E:\V1-1.1.1\pawno\include\PPC_Housing.inc:317
[14:44:35] [debug#2 00083d9c in public cmd_park (playerid=0, params[]=@003def40 "") at E:\V1-1.1.1\pawno\include\PPC_PlayerCommands.inc:651
[14:44:35] [debug#3 native CallLocalFunction () from samp03svr
[14:44:35] [debug#4 00008690 in public OnPlayerCommandText (playerid=0, cmdtext[]=@003def28 "/park") at E:\V1-1.1.1\pawno\include\izcmd.inc:120
[14:44:43] [debugRun time error 4"Array index out of bounds"
[14:44:43] [debug]  Attempted to read/write array element at index 65535 in array of size 2000
[14:44:43] [debugAMX backtrace:
[
14:44:43] [debug#0 0006dda8 in Dialog_GetCarSelectHouse (playerid=0, response=1, listitem=0) at E:\V1-1.1.1\pawno\include\PPC_Dialogs.inc:1645
[14:44:43] [debug#1 000c4cfc in public OnDialogResponse (playerid=0, dialogid=48, response=1, listitem=0, inputtext[]=@003def28 "Totul cu stil <3 !!!") at E:\V1-1.1.1\gamemodes\Lejiune.pwn:1133 
Park cmd:
PHP код:
CMD:park(playeridparams[])
{
    
// Send the command to all admins so they can see it
    
SendAdminText(playerid"/park"params);
    
// Check if the player is inside a vehicle (he must be the driver)
    
if (GetPlayerVehicleSeat(playerid) == 0)
    {
        new 
vidHouseID;
        
// Get the vehicle-id
        
vid GetPlayerVehicleID(playerid);
        
// Get the HouseID to which this vehicle belongs
        
HouseID AVehicleData[vid][BelongsToHouse];
        
// Check if the vehicle is owned (owner-check is not really required, as another player would get kicked out very fast)
        // AND it must belong to a house that the player owns
        
if ((AVehicleData[vid][Owned] == 1) && (HouseID != 0))
        {
            
// Check if the vehicle is in range of the house-entrance (you cannot park a vehicle further away from your house than 150m)
            
if (IsPlayerInRangeOfPoint(playeridParkRangeAHouseData[HouseID][HouseX], AHouseData[HouseID][HouseY], AHouseData[HouseID][HouseZ]))
            {
                new 
Float:xFloat:yFloat:zFloat:rot,query[164];
                
// Get the player's position and angle
                
GetVehiclePos(vidxyz);
                
GetVehicleZAngle(vidrot);
                
// Save those values for the vehicle
                
AVehicleData[vid][SpawnX] = x;
                
AVehicleData[vid][SpawnY] = y;
                
AVehicleData[vid][SpawnZ] = z;
                
AVehicleData[vid][SpawnRot] = rot;
                
mysql_format(g_SQLquerysizeof(query), "UPDATE `vehicles` SET `CarX` = %f, `CarY` = %f, `CarZ` = %f,`CarA` = %f WHERE `ID` = %i",AVehicleData[vid][SpawnX],AVehicleData[vid][SpawnY],AVehicleData[vid][SpawnZ],AVehicleData[vid][SpawnRot],AVehicleData[vid][IDD]);
                
mysql_tquery(g_SQLquery"","");
                
// Find the vehicle in the player's houses
                
for (new iMAX_HOUSESPERPLAYERi++)
                {
                    
// Get the HouseID of the current house
                    
HouseID APlayerData[playerid][Houses][i];
                    
// Loop through all carslots of this house to find the vehicle-id
                    
for (new CarSlotCarSlot 10CarSlot++)
                    {
                        
// Check if this carslot holds the same vehicle-id
                        
if (AHouseData[HouseID][VehicleIDs][CarSlot] == vid)
                        {
                            new 
engine,lights,alarm,doors,bonnet,boot,objective;
                            
House_ReplaceVehicle(HouseIDCarSlot); // Re-create the vehicle at the same spot the player wants to park his vehicle
                            
PutPlayerInVehicle(playeridAHouseData[HouseID][VehicleIDs][CarSlot], 0);
                            
// Turn on the engine
                            
GetVehicleParamsEx(AHouseData[HouseID][VehicleIDs][CarSlot], enginelightsalarmdoorsbonnetbootobjective);
                            
SetVehicleParamsEx(AHouseData[HouseID][VehicleIDs][CarSlot], 1lightsalarmdoorsbonnetbootobjective);
                            break; 
// Stop the for-loop
                        
}
                    }
                }
                
// Let the player know he parked his vehicle
                
SendClientMessage(playerid0x00FF00FF"Ti-ai parcat masina");
            }
            else
            {
                new 
Msg[128];
                
format(Msgsizeof(Msg), "{FF0000}Nu trebuie sa te aflii la mai mult de  %im de casa pentru a parca masina."ParkRange);
                
SendClientMessage(playerid0xFFFFFFFFMsg);
            }
        }
        else
                
SendClientMessage(playerid0xFF0000FF"Nu deti masina");
    }
    else
        
SendClientMessage(playerid0xFF0000FF"Trebuie sa conduci masina");
    
// Let the server know that this was a valid command
    
return 1;

House_AddVehicle :
PHP код:
House_AddVehicle(HouseIDcModelcPaintcComponents[], Float:cxFloat:cyFloat:czFloat:crotCol1Col2)
{
    
// Setup local variables
    
new vidCarSlot;
    
// Get a free carslot from the house
    
CarSlot House_GetFreeCarSlot(HouseID);
    
// Check if there is a free carslot
    
if (CarSlot != -1)
    {
        
// Create a new vehicle and get the vehicle-id
        
vid CreateVehicle(cModelcxcyczcrotCol1Col2600);
        
// Store the vehicle-id in the house's free carslot
        
AHouseData[HouseID][VehicleIDs][CarSlot] = vid;
        
// Save the model of the vehicle
        
AVehicleData[vid][Model] = cModel;
        
// Save the paintjob of the vehicle and apply it
        
AVehicleData[vid][PaintJob] = cPaint;
        if (
cPaint != 0)
            
ChangeVehiclePaintjob(vidcPaint 1);
        
// Also update the car-color
        
ChangeVehicleColor(vidCol1Col2);
        
// Save the colors of the vehicle
        
AVehicleData[vid][Color1] = Col1;
        
AVehicleData[vid][Color2] = Col2;
        
// Save the components of the vehicle and apply them
        
for (new i14i++)
        {
            
AVehicleData[vid][Components][i] = cComponents[i];
            
// Check if the componentslot has a valid component-id
            
if (AVehicleData[vid][Components][i] != 0)
                
AddVehicleComponent(vidAVehicleData[vid][Components][i]); // Add the component to the vehicle
        
}
        
// Save the spawn-data of the vehicle
        
AVehicleData[vid][SpawnX] = cx;
        
AVehicleData[vid][SpawnY] = cy;
        
AVehicleData[vid][SpawnZ] = cz;
        
AVehicleData[vid][SpawnRot] = crot;
        
// Also set the fuel to maximum
        
AVehicleData[vid][Fuel] = MaxFuel;
        
// Also set the owner
        
AVehicleData[vid][Owned] = 1;
        
format(AVehicleData[vid][Owner], 24AHouseData[HouseID][Owner]);
        
// Save the HouseID for the vehicle
        
AVehicleData[vid][BelongsToHouse] = HouseID;
        
AVehicleData[vid][Pid] = AHouseData[HouseID][Pid];
        
// Add a 3DText label to the vehicle, displaying the name of the owner
         
new query[500];
        
mysql_format(g_SQLquerysizeof(query), "INSERT INTO `vehicles` (`ModelID`,`Fuel`,`Color1`,`Color2`,`CarX`,`CarY`,`CarZ`, `CarA`,`Owned`, `Owner`, `BelongsToHouse`,`pid`) VALUES (%i,%i,%i,%i,%f,%f,%f,%f,%i,'%e',%i,%i)",AVehicleData[vid][Model],AVehicleData[vid][Fuel],AVehicleData[vid][Color1],AVehicleData[vid][Color2],AVehicleData[vid][SpawnX],AVehicleData[vid][SpawnY],AVehicleData[vid][SpawnZ],AVehicleData[vid][SpawnRot],AVehicleData[vid][Owned],AVehicleData[vid][Owner],HouseID,AHouseData[HouseID][Pid]);
        
mysql_tquery(g_SQLquery"OnVehicleInsertID","i",vid);
        print(
query);
    }
    else 
// No free carslot was found, return 0
        
return 0;
    
// Exit the function and return the vehicle-id
    
return vid;

House_ReplaceVehicle :
PHP код:
House_ReplaceVehicle(HouseIDCarSlot)
{
    
// Setup local variables
    
new vidcModelcPaintcComponents[14], Float:cxFloat:cyFloat:czFloat:crotCol1Col2Float:HealthcFuel;
    new 
panelsdoorslightstires;
    
// Get the data from the already existing vehicle that was parked before
    
vid AHouseData[HouseID][VehicleIDs][CarSlot];
    
cModel AVehicleData[vid][Model];
    
cPaint AVehicleData[vid][PaintJob];
    
cFuel AVehicleData[vid][Fuel];
    for (new 
i14i++)
        
cComponents[i] = AVehicleData[vid][Components][i];
    
Col1 AVehicleData[vid][Color1];
    
Col2 AVehicleData[vid][Color2];
    
cx AVehicleData[vid][SpawnX];
    
cy AVehicleData[vid][SpawnY];
    
cz AVehicleData[vid][SpawnZ];
    
crot AVehicleData[vid][SpawnRot];
    
GetVehicleHealth(vidHealth);
    
GetVehicleDamageStatus(vidpanelsdoorslightstires);
    
// Delete the vehicle and clear the data
    
Vehicle_Delete(vid);
    
// Create a new vehicle in the same carslot
    
vid House_AddVehicle(HouseIDcModelcPaintcComponentsFloat:cxFloat:cyFloat:czFloat:crotCol1Col2);
    
// Update the fuel of the vehicle to the previous setting
    
AVehicleData[vid][Fuel] = cFuel;
    
// Update the health to what it was before and update the bodywork
    
SetVehicleHealth(vidHealth);
    
UpdateVehicleDamageStatus(vidpanelsdoorslightstires);
    return 
vid;

Vehicle_Delete:
PHP код:
Vehicle_Delete(vid)
{
    
// Setup local variables
    
new HouseIDCarSlot;
    
// Get the HouseID and CarSlot where the vehicle is linked to
    
HouseID AVehicleData[vid][BelongsToHouse];
    
// Check if this was a valid HouseID
    
if (HouseID != 0)
    {
        
// Loop through all carslots of this house to find the vehicle-id
        
for (new i10i++)
        {
            
// Check if this carslot holds the same vehicle-id
            
if (AHouseData[HouseID][VehicleIDs][i] == vid)
            {
                
CarSlot i// The carslot has been found where the vehicle is stored, remember it
                
break; // Stop the for-loop
            
}
        }
        
// Remove the vehicle from the house
        
AHouseData[HouseID][VehicleIDs][CarSlot] = 0;
    }
    
// Delete the vehicle
    
DestroyVehicle(vid);
    
// Clear the data
    
AVehicleData[vid][Owned] = 0;
    
AVehicleData[vid][Owner] = 0;
    
AVehicleData[vid][Model] = 0;
    
AVehicleData[vid][PaintJob] = 0;
    for (new 
i14i++)
        
AVehicleData[vid][Components][i] = 0;
    
AVehicleData[vid][Color1] = 0;
    
AVehicleData[vid][Color2] = 0;
    
AVehicleData[vid][SpawnX] = 0.0;
    
AVehicleData[vid][SpawnY] = 0.0;
    
AVehicleData[vid][SpawnZ] = 0.0;
    
AVehicleData[vid][SpawnRot] = 0.0;
    
AVehicleData[vid][BelongsToHouse] = 0;
    new 
query[264];
    
mysql_format(g_SQLquerysizeof(query), "DELETE FROM `vehicles` WHERE `ID` = %i LIMIT 1"AVehicleData[vid][IDD]);
    
mysql_tquery(g_SQLquery"","");

Dialog_GetCarSelectHouse :
PHP код:
Dialog_GetCarSelectHouse(playeridresponselistitem)
{
    
// Just close the dialog if the player clicked "Cancel"
    
if(!response) return 1;
    
// Get the houseid based on the chosen listitem
    
new HouseID APlayerData[playerid][Houses][listitem];
    
// Check if it was a valid house
    
if (HouseID != 0)
    {
        
// Setup local variables
        
new BuyableCarIndexVehicleList[500], bool:HouseHasCars falseCarSlot;
        
// Store the HouseID, otherwise the next dialog won't be able to get a car from the chosen house
        
APlayerData[playerid][DialogGetCarHouseID] = HouseID;
        
// Check if the house has any cars assigned to it
        
for (CarSlot 0CarSlot 10CarSlot++)
            if (
AHouseData[HouseID][VehicleIDs][CarSlot] != 0)
                
HouseHasCars true;
        
// Check if the house has any cars assigned to it
        
if (HouseHasCars == true)
        {
            
// Add all vehicles to the list
            
for (CarSlot 0CarSlot 10CarSlot++)
            {
                
// Check if the carslot has a vehicle in it
                
if (AHouseData[HouseID][VehicleIDs][CarSlot] != 0)
                {
                    
// Get the index where the first vehicle is found in the ABuyableVehicles array
                    
BuyableCarIndex VehicleBuyable_GetIndex(GetVehicleModel(AHouseData[HouseID][VehicleIDs][CarSlot]));
                    
// Add the name of the vehicle to the list
                    
if (AVehicleData[AHouseData[HouseID][VehicleIDs][CarSlot]][Clamped] == 1)
                        
format(VehicleList500"%s{00FF00}%s (clamped)\n"VehicleListABuyableVehicles[BuyableCarIndex][CarName]);
                    else
                        
format(VehicleList500"%s{00FF00}%s\n"VehicleListABuyableVehicles[BuyableCarIndex][CarName]);
                }
                else
                    
format(VehicleList500TXT_EmptyCarSlotVehicleList);
            }
            
// Ask which vehicle the player wants to teleport to his location
            
ShowPlayerDialog(playeridDialogGetCarSelectCarDIALOG_STYLE_LISTTXT_SelectVehicleToGetVehicleListTXT_DialogButtonSelectTXT_DialogButtonCancel);
        }
        else
            
SendClientMessage(playerid0xFFFFFFFFTXT_NoHouseVehicles);
    }
    else
        
SendClientMessage(playerid0xFFFFFFFFTXT_NoHouseInSlot);
    return 
1;

What can cause this?
Reply
#2

What this (65535 in array of size 2000 ) tells me is you probably didn't check if the player ID is connected. Please can you show me the array which you've defined of a size of 2000?
Reply
#3

Quote:
Originally Posted by [WSF]ThA_Devil
Посмотреть сообщение
What this (65535 in array of size 2000 ) tells me is you probably didn't check if the player ID is connected.
Really? Really? With limit of 1000 players from sa-mp, and defined in gm at 50(max slots from host) , can be 2000? I don't think so
Reply
#4

Quote:
Originally Posted by Banditul18
Посмотреть сообщение
Really? Really? With limit of 1000 players from sa-mp, and defined in gm at 50(max slots from host) , can be 2000? I don't think so
Well, I'd like to see the array that you've created of a size of 2000 first. Also, SA-MP player limit is not responsible for the array sizes you create. Anyways, go in your script and search for "[2000]" so I can know which array is causing the overflow.
Reply
#5

2000 is MAX_VEHICLES, so problem may be with vehicle ID somewhere.
Reply
#6

Quote:
Originally Posted by raydx
Посмотреть сообщение
2000 is MAX_VEHICLES, so problem may be with vehicle ID somewhere.
Yeah, you're right. I checked it and INVALID_VEHICLE_ID is defined as 65535. What would be good if you could find either something in your script with [2000] or [MAX_VEHICLES]


you might want to try this adding a check if vehicle is valid after you get the vehicle ID.

Quote:

vid = GetPlayerVehicleID(playerid);

if(IsValidVehicle(vid)) {

}
You need to add "native IsValidVehicle(vehicleid);" on top of the script for this to work.

or simply:
Quote:

if(vid != INVALID_VEHICLE_ID)

Also, double check if vehicle is valid, if you're trying to destroy it, that causes the same issue.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)