AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Exception Array index out-of-bounds (https://forums.alliedmods.net/showthread.php?t=331788)

Vespa 04-07-2021 12:07

Exception Array index out-of-bounds
 
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

Marttt 04-07-2021 12:29

Re: Exception Array index out-of-bounds
 
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

Vespa 04-07-2021 12:46

Re: Exception Array index out-of-bounds
 
1 Attachment(s)
Hi Marttt, thanks a lot for feedback.
Attached the sp plugin that cause the rror.

Vespa 04-08-2021 07:17

Re: Exception Array index out-of-bounds
 
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

Fyren 04-16-2021 00:25

Re: Exception Array index out-of-bounds
 
Quote:

Originally Posted by Vespa (Post 2743412)
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].


All times are GMT -4. The time now is 04:33.

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