Run time error array index out of bounds[+rep]
#1

Hello, I have tried to debug all these backtraces down to the cause lines and have had no luck, maybe some of you guys might have a anwser. Thank you

[03:01:12] [debug] Run time error 4: "Array index out of bounds"
[03:01:12] [debug] Accessing element at index 10 past array upper bound 9
[03:01:12] [debug] AMX backtrace:
[03:01:12] [debug] #0 00061e24 in FormatHouseWeapons (house=1, string[]=@0x05e85840 "") at C:\Users\Nick\Desktop\Ingenious!\gamemodes\test2.p wn:7070
[03:01:12] [debug] #1 000620d0 in UpdateHouseInfo (houseid=1) at C:\Users\Nick\Desktop\Ingenious!\gamemodes\test2.p wn:7089
[03:01:12] [debug] #2 000cf45c in public GlobalSaving () at C:\Users\Nick\Desktop\Ingenious!\gamemodes\test2.p wn:15460

Код:
stock FormatHouseWeapons(house, string[])
{
	new wstr[256];
	new tmp[64];
	for(new a = 1; a < MAX_HOUSE_WEAPONS; a++)
	{
		new w = HouseInfo[house][hWeapon][a];
		new am = HouseInfo[house][hAmmo][a];
		if(a == 1)
		{
			format(tmp,sizeof(tmp),"%d=%d",w,am);
		}
		else
		{
			format(tmp,sizeof(tmp),"|%d=%d",w,am);
		}
		strins(wstr,tmp,strlen(wstr));
	}
	return format(string, 256, "%s", wstr);
}
Код:
stock UpdateHouseInfo(houseid)
{
	new weapons[256];
	FormatHouseWeapons(houseid, weapons);
	format(query, sizeof(query), "UPDATE `houses` SET `owner` = '%s', `owned` = %d, `locked` = %d, `price`= %d, `levelbuy`= %d, `rentprice` = %d, `rentable` = %d, `interior` = %d, `world` = %d, `cash` = %d, `furnitures` = %d WHERE `id` = %d",
	HouseInfo[houseid][hOwner],
	HouseInfo[houseid][hOwned],
	HouseInfo[houseid][hLocked],
	HouseInfo[houseid][hPrice],
	HouseInfo[houseid][hLevelbuy],
	HouseInfo[houseid][hRentprice],
	HouseInfo[houseid][hRentable],
	HouseInfo[houseid][hInterior],
	HouseInfo[houseid][hWorld],
	HouseInfo[houseid][hCash],
	HouseInfo[houseid][hFurnitures],
	HouseInfo[houseid][hID]);
	mysql_function_query(dbHandle, query, false, "", "");
	format(query, sizeof(query), "UPDATE `houses` SET `checkx` = %f, `checky` = %f, `checkz` = %f, `weapons` = '%s', `radio` = %d WHERE `id` = %d",
	HouseInfo[houseid][hCheckPosX],
	HouseInfo[houseid][hCheckPosY],
	HouseInfo[houseid][hCheckPosZ],
	weapons,
	HouseInfo[houseid][hRadio],
	HouseInfo[houseid][hID]);
	mysql_function_query(dbHandle, query, false, "", "");
	return 1;
}
\
Код:
public GlobalSaving()
{
	//-------------------------------------------------
	foreach(Player, i)
	{
		SavePlayerStats(i);
	}
	//-------------------------------------------------
	for(new i = 0; i < MAX_PARK_METERS; i++)
	{
		if(ParkMeters[i][parkOn])
		{
			SaveParkMeter(i);
		}
	}
	//-------------------------------------------------
	for(new i = 0; i < MAX_VEHICLES; i++)
	{
		if(VehicleInfo[i][carOwned] == 1)
		{
			SaveVehicle(i);
		}
	}
	//-------------------------------------------------
	for(new i = 1; i < MAX_HOUSES; i++)
	{
		if(HouseInfo[i][hHouseOn] == 1 && HouseInfo[i][hOwned] == 1)
		{
			UpdateHouseInfo(i);
		}
	}
	//-------------------------------------------------
	for(new i = 0; i < MAX_BIZ; i++)
	{
		if(BizInfo[i][bizOn] == 1)
		{
			UpdateBizInfo(i);
		}
	}
	//-------------------------------------------------
	for(new i = 0; i < MAX_FACTIONS; i++)
	{
		if(Factions[i][fON] == 1)
		{
			SaveFaction(i);
		}
	}
	//-------------------------------------------------
	SavePlants();
	return 1;
}
Reply
#2

I dont believe this will do any harm whatsoever.
This happens when you try to allocate data in a array from a variable bigger than the array is limited to.

Example:
#define MAX_SOMETHING 5
new test[5];

Not correct:
Код:
	for(new h=0; h<=MAX_SOMETHING; h++)
	{
		test[h]=1;
	}
Correct:
Код:
	for(new h=0; h<MAX_SOMETHING; h++)
	{
		test[h]=1;
	}
Reply
#3

After reviewing your code I'd like to point this out:
Код:
	new weapons[256];
	FormatHouseWeapons(houseid, weapons);
What are you trying to do here?

I believe you need to change
Код:
stock FormatHouseWeapons(house, string[])
to:
Код:
stock FormatHouseWeapons(house)
Add: new string[256]; under the stock. (Choose a approperiate array size, I dont know how far your loop will go so I'll stick here with 256)

Change:
Код:
FormatHouseWeapons(houseid, weapons);
to:
Код:
FormatHouseWeapons(houseid);
Reply
#4

Well with FormatHouseWeapons i had string[] because at the bottom im formating the string (256) to %s like so

return format(string, 256, "%s", wstr);

my new wstr is my wstring

which are defined here,

new wstring1[56], gunname1[32];
GetWeaponName(PlayerInfo[id][pPerm1],gunname1,sizeof(gunname1));
if(PlayerInfo[id][pPerm1] == 0) { wstring1 = "None"; }
else if(PlayerInfo[id][pPerm1] > 0) { wstring1 = gunname1; }
else { wstring1 = "None"; }

new wstring2[56], gunname2[32];
GetWeaponName(PlayerInfo[id][pPerm2],gunname2,sizeof(gunname2));
if(PlayerInfo[id][pPerm2] == 0) { wstring2 = "None"; }
else if(PlayerInfo[id][pPerm2] > 0) { wstring2 = gunname2; }
else { wstring2 = "None"; }

new wstring3[56], gunname3[32];
GetWeaponName(PlayerInfo[id][pMeleeWep],gunname3,sizeof(gunname3));
if(PlayerInfo[id][pMeleeWep] == 0) { wstring3 = "None"; }
else if(PlayerInfo[id][pMeleeWep] > 0) { wstring3 = gunname3; }
else { wstring3 = "None"; }
Reply
#5

Just do as I told you to and tell me if it worked or not.
Reply
#6

Show define MAX_HOUSE_WEAPONS and HouseInfo enum

pawn Код:
stock FormatHouseWeapons(house, string[], s_size = sizeof(string))
{
    string[0] = EOS;

    for(new a = 1; a < MAX_HOUSE_WEAPONS; a++)
        format(string, s_size, "%s%d=%d|", string, HouseInfo[house][hWeapon][a],HouseInfo[house][hAmmo][a]);

    if(string[0])
        string[strlen(string) - 1] = EOS;
}
Reply
#7

No it didnt work, its outputed the same errors, just different lines, the backtrace calls whenever a player leaves the server.


Код:
#define MAX_HOUSE_WEAPONS 21 // Needs to be plus 1
Код:
enum HOUSE_INFO
{
	hID,
	Text3D:hLabel,
	hCheckPoint,
	Float:hEntranceX,
	Float:hEntranceY,
	Float:hEntranceZ,
	Float:hExitX,
	Float:hExitY,
	Float:hExitZ,
	hInfo[128],
	hOwner[MAX_PLAYER_NAME],
	hOwned,
	hLocked,
	hPrice,
	hLevelbuy,
	hRentprice,
	hRentable,
	hInterior,
	hWorld,
	hCash,
	hFurnitures,
	hWeapon[10],
	hAmmo[10],
	hHouseOn,
	Float:hCheckPosX,
	Float:hCheckPosY,
	Float:hCheckPosZ,
	hRadio,
	hRadioOn,
	hRadioURL[256]
};
new HouseInfo[MAX_HOUSES][HOUSE_INFO];
[15:50:38] [debug] Run time error 4: "Array index out of bounds"
[15:50:38] [debug] Accessing element at index 10 past array upper bound 9
[15:50:38] [debug] AMX backtrace:
[15:50:38] [debug] #0 00062014 in FormatHouseWeapons (house=1) at C:\Users\Nick\Desktop\Ingenious!\gamemodes\test2.p wn:7087

Код:
stock FormatHouseWeapons(house)
{
	new string[256];
	new wstr[256];
	new tmp[64];
	for(new a=1; a<MAX_HOUSE_WEAPONS; a++)
	{
		new w = HouseInfo[house][hWeapon][a]; > Error line 7087
		new am = HouseInfo[house][hAmmo][a];
		if(a == 1)
		{
			format(tmp,sizeof(tmp),"%d=%d",w,am);
		}
		else
		{
			format(tmp,sizeof(tmp),"|%d=%d",w,am);
		}
		strins(wstr,tmp,strlen(wstr));
	}
	return format(string, 256, "%s", wstr);
}
[15:50:38] [debug] #1 000622b4 in UpdateHouseInfo (houseid=1) at C:\Users\Nick\Desktop\Ingenious!\gamemodes\test2.p wn:7106

Код:
stock UpdateHouseInfo(houseid)
{
	new weapons[256];
	FormatHouseWeapons(houseid);
	format(query, sizeof(query), "UPDATE `houses` SET `owner` = '%s', `owned` = %d, `locked` = %d, `price`= %d, `levelbuy`= %d, `rentprice` = %d, `rentable` = %d, `interior` = %d, `world` = %d, `cash` = %d, `furnitures` = %d WHERE `id` = %d", > Error Line 7106
	HouseInfo[houseid][hOwner],
	HouseInfo[houseid][hOwned],
	HouseInfo[houseid][hLocked],
	HouseInfo[houseid][hPrice],
	HouseInfo[houseid][hLevelbuy],
	HouseInfo[houseid][hRentprice],
	HouseInfo[houseid][hRentable],
	HouseInfo[houseid][hInterior],
	HouseInfo[houseid][hWorld],
	HouseInfo[houseid][hCash],
	HouseInfo[houseid][hFurnitures],
	HouseInfo[houseid][hID]);
	mysql_function_query(dbHandle, query, false, "", "");
	format(query, sizeof(query), "UPDATE `houses` SET `checkx` = %f, `checky` = %f, `checkz` = %f, `weapons` = '%s', `radio` = %d WHERE `id` = %d",
	HouseInfo[houseid][hCheckPosX],
	HouseInfo[houseid][hCheckPosY],
	HouseInfo[houseid][hCheckPosZ],
	weapons,
	HouseInfo[houseid][hRadio],
	HouseInfo[houseid][hID]);
	mysql_function_query(dbHandle, query, false, "", "");
	return 1;
}
[15:50:38] [debug] #2 000de510 in public GlobalSaving () at C:\Users\Nick\Desktop\Ingenious!\gamemodes\test2.p wn:15863

Код:
public GlobalSaving()
{
	//-------------------------------------------------
	foreach(Player, i)
	{
		SavePlayerStats(i);
	}
	//-------------------------------------------------
	for(new i = 0; i < MAX_PARK_METERS; i++)
	{
		if(ParkMeters[i][parkOn])
		{
			SaveParkMeter(i);
		}
	}
	//-------------------------------------------------
	for(new i = 0; i < MAX_VEHICLES; i++)
	{
		if(VehicleInfo[i][carOwned] == 1)
		{
			SaveVehicle(i);
		}
	}
	//-------------------------------------------------
	for(new i = 1; i < MAX_HOUSES; i++)
	{
		if(HouseInfo[i][hHouseOn] == 1 && HouseInfo[i][hOwned] == 1)
		{
			UpdateHouseInfo(i); > Error Line 15863
		}
	}
	//-------------------------------------------------
	for(new i = 0; i < MAX_BIZ; i++)
	{
		if(BizInfo[i][bizOn] == 1)
		{
			UpdateBizInfo(i);
		}
	}
	//-------------------------------------------------
	for(new i = 0; i < MAX_FACTIONS; i++)
	{
		if(Factions[i][fON] == 1)
		{
			SaveFaction(i);
		}
	}
	//-------------------------------------------------
	SavePlants();
	return 1;
}
Also gave a new error in the console,

[15:17:19] [debug] #0 000acfd8 in AssignHouseWeapons (house=1, str[]=@0x05e8639c "0=0|0=0|0=0|0=0|0=0|0=0|0=0|0=...") at C:\Users\Nick\Desktop\Ingenious!\gamemodes\test2.p wn:11818

Код:
stock AssignHouseWeapons(house, str[])
{
	new wtmp[MAX_HOUSE_WEAPONS][64];
	explode(wtmp,str,"|");
	for(new z = 1; z < MAX_HOUSE_WEAPONS; z++)
	{
		new wtmp2[2][64];
		explode(wtmp2,wtmp[z-1],"=");
		HouseInfo[house][hWeapon][z] = strval(wtmp2[0]);
		HouseInfo[house][hAmmo][z] = strval(wtmp2[1]);
	}
}
Reply
#8

Atleast mark the lines in the code from the debug that points these out.
Reply
#9

Loop is with MAX_HOUSE_WEAPONS (21) but you got hWeapon[10], hAmmo[10] in enum
Reply
#10

Updated with marks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)