Raised This Month: $12 Target: $400
 3% 

Exception Array index out-of-bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Vespa
New Member
Join Date: Dec 2020
Old 04-07-2021 , 12:07   Exception Array index out-of-bounds
Reply With Quote #1

Hi, I'm totally new in SourcePawn language, so I'm trying to learn and understand the language and scripting.
In my server I have a plugin that arise the following errors in log file:
Code:
SourceMod error session started
L 04/06/2021 - 20:03:18: Info (map "embassy_coop") (file "/home/insserver/serverfiles/insurgency/addons/sourcemod/logs/errors_20210406.log")
L 04/06/2021 - 20:03:18: [SM] Exception reported: Array index out-of-bounds (index -1, limit 13)
L 04/06/2021 - 20:03:18: [SM] Blaming: c_dy_respawn_naong_ai_director_S3.smx
L 04/06/2021 - 20:03:18: [SM] Call stack trace:
L 04/06/2021 - 20:03:18: [SM]   [1] Line 2200, c_dy_respawn_naong_ai_director_S3.sp::Timer_CheckEnemyAway
So I check the director plugin to find the issue...
The Timer_CheckEnemyAway is defined here:
Code:
CreateTimer(1.0, Timer_CheckEnemyAway,_ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
after that, it's called in the following function:
Code:
// Check enemy is stuck
public Action:Timer_CheckEnemyAway(Handle:Timer)
{
	//Remove bot weapons when static killed to reduce server performance on dropped items.
	new primaryRemove = 1, secondaryRemove = 1, grenadesRemove = 1;
	// Check round state
	if (g_iRoundStatus == 0) return Plugin_Continue;
	
	if (Ins_InCounterAttack())
	{
		g_checkStaticAmtCntrAway = g_checkStaticAmtCntrAway - 1;
		if (g_checkStaticAmtCntrAway <= 0)
		{
			for (new enemyBot = 1; enemyBot <= MaxClients; enemyBot++)
			{	
				if (IsClientInGame(enemyBot) && IsFakeClient(enemyBot))
				{
					new m_iTeam = GetClientTeam(enemyBot);
					if (IsPlayerAlive(enemyBot) && m_iTeam == TEAM_2_INS)
					{
						// Get current position
						decl Float:enemyPos[3];
						GetClientAbsOrigin(enemyBot, Float:enemyPos);
						
						// Get distance
						new Float:tDistance;
						new Float:capDistance;
						tDistance = GetVectorDistance(enemyPos, g_enemyTimerAwayPos[enemyBot]);
						if (g_isCheckpoint == 1)
						{
							new m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
							Ins_ObjectiveResource_GetPropVector("m_vCPPositions",m_vCPPositions[m_nActivePushPointIndex],m_nActivePushPointIndex);
							capDistance = GetVectorDistance(enemyPos,m_vCPPositions[m_nActivePushPointIndex]);
						}
						else 
							capDistance = 801;
						// If enemy position is static, kill him
						if (tDistance <= 150 && capDistance > 2500) 
						{
							//PrintToServer("ENEMY STATIC - KILLING");
							RemoveWeapons(enemyBot, primaryRemove, secondaryRemove, grenadesRemove);
							ForcePlayerSuicide(enemyBot);
							AddLifeForStaticKilling(enemyBot);
						}
						// Update current position
						else
						{
							g_enemyTimerAwayPos[enemyBot] = enemyPos;
						}
					}
				}
			}
			g_checkStaticAmtCntrAway = 12;
		}
	}
	else
	{
		g_checkStaticAmtAway = g_checkStaticAmtAway - 1;
		if (g_checkStaticAmtAway <= 0)
		{
			for (new enemyBot = 1; enemyBot <= MaxClients; enemyBot++)
			{	
				if (IsClientInGame(enemyBot) && IsFakeClient(enemyBot))
				{
					new m_iTeam = GetClientTeam(enemyBot);
					if (IsPlayerAlive(enemyBot) && m_iTeam == TEAM_2_INS)
					{
						// Get current position
						decl Float:enemyPos[3];
						GetClientAbsOrigin(enemyBot, Float:enemyPos);
						
						// Get distance
						new Float:tDistance;
						new Float:capDistance;
						tDistance = GetVectorDistance(enemyPos, g_enemyTimerAwayPos[enemyBot]);
						//Check point distance
						if (g_isCheckpoint == 1)
						{
							new m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
							Ins_ObjectiveResource_GetPropVector("m_vCPPositions",m_vCPPositions[m_nActivePushPointIndex],m_nActivePushPointIndex);
							capDistance = GetVectorDistance(enemyPos,m_vCPPositions[m_nActivePushPointIndex]);
						}
						// If enemy position is static, kill him
						if (tDistance <= 150 && capDistance > 1200) 
						{
							//PrintToServer("ENEMY STATIC - KILLING");
							RemoveWeapons(enemyBot, primaryRemove, secondaryRemove, grenadesRemove);
							ForcePlayerSuicide(enemyBot);
							AddLifeForStaticKilling(enemyBot);
						}
						// Update current position
						else
						{ 
							g_enemyTimerAwayPos[enemyBot] = enemyPos;
						}
					}
				}
			}
			g_checkStaticAmtAway = 30; 
		}
	}
	
	return Plugin_Continue;
}
I don't understand what's the array causing the error...any hint to fix the issue? Thanks a lot for any help

Last edited by Vespa; 04-07-2021 at 12:12.
Vespa is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 04-07-2021 , 12:29   Re: Exception Array index out-of-bounds
Reply With Quote #2

You should also paste the exact line that gives this exception too cause looking at your post I don't know which line is number 2200.
Or attach the full .sp file
__________________
Marttt is offline
Vespa
New Member
Join Date: Dec 2020
Old 04-07-2021 , 12:46   Re: Exception Array index out-of-bounds
Reply With Quote #3

Hi Marttt, thanks a lot for feedback.
Attached the sp plugin that cause the rror.
Attached Files
File Type: sp Get Plugin or Get Source (c_dy_respawn_naong_ai_director_S3.sp - 41 views - 287.6 KB)
Vespa is offline
Vespa
New Member
Join Date: Dec 2020
Old 04-08-2021 , 07:17   Re: Exception Array index out-of-bounds
Reply With Quote #4

In any case, in short....the row n.2200 is the following:

Code:
new m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
Thanks for any feedback
Vespa is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 04-16-2021 , 00:25   Re: Exception Array index out-of-bounds
Reply With Quote #5

Quote:
Originally Posted by Vespa View Post
In any case, in short....the row n.2200 is the following:

Code:
new m_nActivePushPointIndex = Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
Thanks for any feedback
Line 2200 is the line after what you pasted there.

PHP Code:
new m_nActivePushPointIndex Ins_ObjectiveResource_GetProp("m_nActivePushPointIndex");
Ins_ObjectiveResource_GetPropVector("m_vCPPositions",m_vCPPositions[m_nActivePushPointIndex],m_nActivePushPointIndex); 
In your original post, Exception reported: Array index out-of-bounds (index -1, limit 13) means that you gave an index of -1 and the array you indexed has 13 elements. I'd guess what's happening is that prop is -1, so you're effectively doing m_vCPPositions[-1].
Fyren is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:09.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode