SA-MP Forums Archive
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=505998)



Array index out of bounds - ChristianIvann09 - 11.04.2014

hi,

i just wanted to know if i can fix this warnings (which cause my server to lag i guess)

Код:
[11:18:35] [debug] Run time error 4: "Array index out of bounds"
[11:18:35] [debug]  Accessing element at index 999 past array upper bound 500
[11:18:35] [debug] AMX backtrace:
[11:18:35] [debug] #0 00077eb0 in public OnPlayerStateChange (0x00000002, 0x00000001, 0x00000003) from PHRP_V1.2.amx
OnPlayerKeyStateChange
http://pastebin.com/7DXHLWeg


thanks!


Re: Array index out of bounds - Lidor124 - 11.04.2014

Might you know what key you press and then server crash?


Re: Array index out of bounds - ChristianIvann09 - 11.04.2014

Quote:
Originally Posted by Lidor124
Посмотреть сообщение
Might you know what key you press and then server crash?
My server didnt actually crased but its lagging when they pressing "y"

or KEY_YES


Re: Array index out of bounds - Sithis - 11.04.2014

Check the defined size of:

for(new veh = 1; veh < MAX_VEHICLES; veh++)

for(new i = 0; i < sizeof(DDoorsInfo); i++) {

for(new i = 0; i < sizeof(FamilyInfo); i++) {

for(new i = 0; i < sizeof(HouseInfo); i++) {


Re: Array index out of bounds - Konstantinos - 11.04.2014

https://sampforum.blast.hk/showthread.php?tid=505791


Re: Array index out of bounds - ChristianIvann09 - 11.04.2014

Quote:
Originally Posted by Sithis
Посмотреть сообщение
Check the defined size of:

for(new veh = 1; veh < MAX_VEHICLES; veh++)

for(new i = 0; i < sizeof(DDoorsInfo); i++) {

for(new i = 0; i < sizeof(FamilyInfo); i++) {

for(new i = 0; i < sizeof(HouseInfo); i++) {
Whats this?

Can you please elaborate?


Re: Array index out of bounds - ChristianIvann09 - 11.04.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Like this??:

Код:
if (IsKeyJustDown(KEY_FIRE, newkeys, oldkeys))
	{
		if( PlayerInfo[playerid][pC4Used] == 1 )
		{
            if (0 <= GoChase[playerid] < sizeof (PlayerInfo))
			{
				if(IsPlayerInRangeOfPoint(GoChase[playerid], 12.0, GetPVarFloat(playerid, "DYN_C4_FLOAT_X"), GetPVarFloat(playerid, "DYN_C4_FLOAT_Y"), GetPVarFloat(playerid, "DYN_C4_FLOAT_Z")))
				{
     				if(PlayerInfo[GoChase[playerid]][pHeadValue] >= 1)
					{
						if(PlayerInfo[playerid][pMember] == 8 || PlayerInfo[playerid][pLeader] == 8)
						{
							new string[128];
							new takemoney = PlayerInfo[GoChase[playerid]][pHeadValue] / 4 * 2;
							GivePlayerCash(playerid, takemoney);
							GivePlayerCash(GoChase[playerid], -takemoney);
							format(string,sizeof(string),"Hitman %s has fulfilled the contract on %s and collected $%d",GetPlayerNameEx(playerid),GetPlayerNameEx(GoChase[playerid]),PlayerInfo[GoChase[playerid]][pHeadValue] / 4 * 2);
							SendFamilyMessage(8, COLOR_YELLOW, string);
							format(string,sizeof(string),"You have been critically injured by a Hitman and lost $%d!",takemoney);
							ResetPlayerWeaponsEx(GoChase[playerid]);
							// SpawnPlayer(GoChase[playerid]);
							SendClientMessageEx(GoChase[playerid], COLOR_YELLOW, string);
							PlayerInfo[GoChase[playerid]][pHeadValue] = 0;
							PlayerInfo[playerid][pCHits] += 1;
							SetPlayerHealth(GoChase[playerid], 0.0);
							// KillEMSQueue(GoChase[playerid]);
							GotHit[GoChase[playerid]] = 0;
							GetChased[GoChase[playerid]] = 999;
							GoChase[playerid] = 999;
						}
					}
				}
			}



Re: Array index out of bounds - Konstantinos - 11.04.2014

The indentation is a bit.. but I guess it's fine foe the above code. It should check the value of it before using.


Re: Array index out of bounds - ChristianIvann09 - 11.04.2014

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
The indentation is a bit.. but I guess it's fine foe the above code. It should check the value of it before using.
i tried but it still gives me the same warnings


Re: Array index out of bounds - Konstantinos - 11.04.2014

Quote:
Originally Posted by ChristianIvann09
Посмотреть сообщение
i tried but it still gives me the same warnings
Make sure you check if it's in bounds for all the lines that uses GoChase[playerid].

Debug info can help you to get the exact line if you compile your scripts correctly with it.