Raised This Month: $ Target: $400
 0% 

Run time error 4: index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JoneM
Junior Member
Join Date: May 2023
Old 10-09-2023 , 06:11   Run time error 4: index out of bounds
Reply With Quote #1

Hi, in logs always get the same error all the time, what does mean "index of bounds" and how to fix this? Plugin works, but get the errors..

L 10/09/2023 - 03:10:04: [AMXX] Displaying debug trace (plugin "plugin.amxx", version "1.0.0")
L 10/09/2023 - 03:10:04: [AMXX] Run time error 4: index out of bounds
L 10/09/2023 - 03:10:04: [AMXX] [0] plugin.sma::CBasePlayerWeapon_DefaultDeploy (line 201)


L 10/09/2023 - 11:52:00: [AMXX] Displaying debug trace (plugin "plugin.amxx", version "1.0.0")
L 10/09/2023 - 11:52:00: [AMXX] Run time error 4: index out of bounds
L 10/09/2023 - 11:52:00: [AMXX] [0] plugin.sma::CBasePlayerWeapon_DefaultDeploy (line 201)
L 10/09/2023 - 11:52:00: [AMXX] Displaying debug trace (plugin "plugin.amxx", version "1.0.0")
L 10/09/2023 - 11:52:00: [AMXX] Run time error 4: index out of bounds
L 10/09/2023 - 11:52:00: [AMXX] [0] plugin.sma::CWeaponBox_SetModel (line 229)




201 line:
PHP Code:
public CBasePlayerWeapon_DefaultDeploy(pWeaponviewModel[], weaponModel[], animanimExt[], skiplocal)
{
    if (
get_entvar(pWeaponvar_impulse) != 0)
        return 
HC_CONTINUE;
    new 
iId get_member(pWeaponm_iId);
    new 
iNum g_iPlayerSkins[get_member(pWeaponm_pPlayer)][iId];
    if (
iNum == -1)
        return 
HC_CONTINUE;
    
    for (new 
iaWeapons[WEAPON_DATA]; g_iWeaponSkinsNumi++)
    {
        
ArrayGetArray(g_aWeaponSkinsiaWeapons);
        if (
aWeapons[WEAPON_ID] != iId)
            continue;
        if (
iNum != i)
            continue;
        if (
aWeapons[V_MODEL][0])
            
SetHookChainArg(2ATYPE_STRINGaWeapons[V_MODEL]);
        if (
aWeapons[P_MODEL][0])
            
SetHookChainArg(3ATYPE_STRINGaWeapons[P_MODEL]);
        break;
    }
    return 
HC_CONTINUE;
}



public 
CWeaponBox_SetModel(pWeaponBox, const szModel[])
{
    new 
pWeapon UTIL_GetWeaponBoxWeapon(pWeaponBox);
229 line    if (pWeapon == NULLENT)
        return 
HC_CONTINUE;
    if (
get_entvar(pWeaponvar_impulse) != 0)
        return 
HC_CONTINUE;
    new 
iId get_member(pWeaponm_iId);
    new 
iNum g_iPlayerSkins[get_entvar(pWeaponBoxvar_owner)][iId];
    if (
iNum == -1)
        return 
HC_CONTINUE;
    for (new 
iaWeapons[WEAPON_DATA]; g_iWeaponSkinsNumi++)
    {
        
ArrayGetArray(g_aWeaponSkinsiaWeapons);
        if (
aWeapons[WEAPON_ID] != iId)
            continue;
        if (
iNum != i)
            continue;
        if (
aWeapons[W_MODEL][0])
            
SetHookChainArg(2ATYPE_STRINGaWeapons[W_MODEL]);
        break;
    }
    return 
HC_CONTINUE;


Last edited by JoneM; 10-10-2023 at 01:17. Reason: correction
JoneM is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 10-09-2023 , 08:34   Re: Run time error 4: index out of bounds
Reply With Quote #2

show the full code and use the php tag to highlight it [php]code here[/php]
__________________
mlibre is offline
JoneM
Junior Member
Join Date: May 2023
Old 10-10-2023 , 01:20   Re: Run time error 4: index out of bounds
Reply With Quote #3

sss

Last edited by JoneM; 10-11-2023 at 01:23. Reason: no help, fixed
JoneM is offline
Ace67
Senior Member
Join Date: Sep 2020
Location: France
Old 10-13-2023 , 11:38   Re: Run time error 4: index out of bounds
Reply With Quote #5

Quote:
Originally Posted by JoneM View Post
Hi, in logs always get the same error all the time, what does mean "index of bounds" and how to fix this? Plugin works, but get the errors..

L 10/09/2023 - 03:10:04: [AMXX] Displaying debug trace (plugin "plugin.amxx", version "1.0.0")
L 10/09/2023 - 03:10:04: [AMXX] Run time error 4: index out of bounds
L 10/09/2023 - 03:10:04: [AMXX] [0] plugin.sma::CBasePlayerWeapon_DefaultDeploy (line 201)


L 10/09/2023 - 11:52:00: [AMXX] Displaying debug trace (plugin "plugin.amxx", version "1.0.0")
L 10/09/2023 - 11:52:00: [AMXX] Run time error 4: index out of bounds
L 10/09/2023 - 11:52:00: [AMXX] [0] plugin.sma::CBasePlayerWeapon_DefaultDeploy (line 201)
L 10/09/2023 - 11:52:00: [AMXX] Displaying debug trace (plugin "plugin.amxx", version "1.0.0")
L 10/09/2023 - 11:52:00: [AMXX] Run time error 4: index out of bounds
L 10/09/2023 - 11:52:00: [AMXX] [0] plugin.sma::CWeaponBox_SetModel (line 229)




201 line:
PHP Code:
public CBasePlayerWeapon_DefaultDeploy(pWeaponviewModel[], weaponModel[], animanimExt[], skiplocal)
{
    if (
get_entvar(pWeaponvar_impulse) != 0)
        return 
HC_CONTINUE;
    new 
iId get_member(pWeaponm_iId);
    new 
iNum g_iPlayerSkins[get_member(pWeaponm_pPlayer)][iId];
    if (
iNum == -1)
        return 
HC_CONTINUE;
    
    for (new 
iaWeapons[WEAPON_DATA]; g_iWeaponSkinsNumi++)
    {
        
ArrayGetArray(g_aWeaponSkinsiaWeapons);
        if (
aWeapons[WEAPON_ID] != iId)
            continue;
        if (
iNum != i)
            continue;
        if (
aWeapons[V_MODEL][0])
            
SetHookChainArg(2ATYPE_STRINGaWeapons[V_MODEL]);
        if (
aWeapons[P_MODEL][0])
            
SetHookChainArg(3ATYPE_STRINGaWeapons[P_MODEL]);
        break;
    }
    return 
HC_CONTINUE;
}



public 
CWeaponBox_SetModel(pWeaponBox, const szModel[])
{
    new 
pWeapon UTIL_GetWeaponBoxWeapon(pWeaponBox);
229 line    if (pWeapon == NULLENT)
        return 
HC_CONTINUE;
    if (
get_entvar(pWeaponvar_impulse) != 0)
        return 
HC_CONTINUE;
    new 
iId get_member(pWeaponm_iId);
    new 
iNum g_iPlayerSkins[get_entvar(pWeaponBoxvar_owner)][iId];
    if (
iNum == -1)
        return 
HC_CONTINUE;
    for (new 
iaWeapons[WEAPON_DATA]; g_iWeaponSkinsNumi++)
    {
        
ArrayGetArray(g_aWeaponSkinsiaWeapons);
        if (
aWeapons[WEAPON_ID] != iId)
            continue;
        if (
iNum != i)
            continue;
        if (
aWeapons[W_MODEL][0])
            
SetHookChainArg(2ATYPE_STRINGaWeapons[W_MODEL]);
        break;
    }
    return 
HC_CONTINUE;

In both functions, I added checks to ensure that iNum is within the bounds of the g_iWeaponSkins array to prevent the "index out of bounds" error.

Try it and let me know

Code:
public CBasePlayerWeapon_DefaultDeploy(pWeapon, viewModel[], weaponModel[], anim, animExt[], skiplocal)
{
    if (get_entvar(pWeapon, var_impulse) != 0)
        return HC_CONTINUE;
    new iId = get_member(pWeapon, m_iId);
    new iNum = g_iPlayerSkins[get_member(pWeapon, m_pPlayer)][iId];
    if (iNum == -1 || iNum >= g_iWeaponSkinsNum)
        return HC_CONTINUE;

    for (new i, aWeapons[WEAPON_DATA]; i < g_iWeaponSkinsNum; i++)
    {
        ArrayGetArray(g_aWeaponSkins, i, aWeapons);
        if (aWeapons[WEAPON_ID] != iId)
            continue;
        if (iNum != i)
            continue;
        if (aWeapons[V_MODEL][0])
            SetHookChainArg(2, ATYPE_STRING, aWeapons[V_MODEL]);
        if (aWeapons[P_MODEL][0])
            SetHookChainArg(3, ATYPE_STRING, aWeapons[P_MODEL]);
        break;
    }
    return HC_CONTINUE;
}
Code:
public CWeaponBox_SetModel(pWeaponBox, const szModel[])
{
    new pWeapon = UTIL_GetWeaponBoxWeapon(pWeaponBox);
    if (pWeapon == NULLENT)
        return HC_CONTINUE;
    if (get_entvar(pWeapon, var_impulse) != 0)
        return HC_CONTINUE;
    new iId = get_member(pWeapon, m_iId);
    new iNum = g_iPlayerSkins[get_entvar(pWeaponBox, var_owner)][iId];
    if (iNum == -1 || iNum >= g_iWeaponSkinsNum)
        return HC_CONTINUE;

    for (new i, aWeapons[WEAPON_DATA]; i < g_iWeaponSkinsNum; i++)
    {
        ArrayGetArray(g_aWeaponSkins, i, aWeapons);
        if (aWeapons[WEAPON_ID] != iId)
            continue;
        if (iNum != i)
            continue;
        if (aWeapons[W_MODEL][0])
            SetHookChainArg(2, ATYPE_STRING, aWeapons[W_MODEL]);
        break;
    }
    return HC_CONTINUE;
}
Ace67 is offline
JoneM
Junior Member
Join Date: May 2023
Old 10-24-2023 , 02:55   Re: Run time error 4: index out of bounds
Reply With Quote #6

Quote:
Originally Posted by Ace67 View Post
In both functions, I added checks to ensure that iNum is within the bounds of the g_iWeaponSkins array to prevent the "index out of bounds" error.

Try it and let me know

Code:
public CBasePlayerWeapon_DefaultDeploy(pWeapon, viewModel[], weaponModel[], anim, animExt[], skiplocal)
{
    if (get_entvar(pWeapon, var_impulse) != 0)
        return HC_CONTINUE;
    new iId = get_member(pWeapon, m_iId);
    new iNum = g_iPlayerSkins[get_member(pWeapon, m_pPlayer)][iId];
    if (iNum == -1 || iNum >= g_iWeaponSkinsNum)
        return HC_CONTINUE;

    for (new i, aWeapons[WEAPON_DATA]; i < g_iWeaponSkinsNum; i++)
    {
        ArrayGetArray(g_aWeaponSkins, i, aWeapons);
        if (aWeapons[WEAPON_ID] != iId)
            continue;
        if (iNum != i)
            continue;
        if (aWeapons[V_MODEL][0])
            SetHookChainArg(2, ATYPE_STRING, aWeapons[V_MODEL]);
        if (aWeapons[P_MODEL][0])
            SetHookChainArg(3, ATYPE_STRING, aWeapons[P_MODEL]);
        break;
    }
    return HC_CONTINUE;
}
Code:
public CWeaponBox_SetModel(pWeaponBox, const szModel[])
{
    new pWeapon = UTIL_GetWeaponBoxWeapon(pWeaponBox);
    if (pWeapon == NULLENT)
        return HC_CONTINUE;
    if (get_entvar(pWeapon, var_impulse) != 0)
        return HC_CONTINUE;
    new iId = get_member(pWeapon, m_iId);
    new iNum = g_iPlayerSkins[get_entvar(pWeaponBox, var_owner)][iId];
    if (iNum == -1 || iNum >= g_iWeaponSkinsNum)
        return HC_CONTINUE;

    for (new i, aWeapons[WEAPON_DATA]; i < g_iWeaponSkinsNum; i++)
    {
        ArrayGetArray(g_aWeaponSkins, i, aWeapons);
        if (aWeapons[WEAPON_ID] != iId)
            continue;
        if (iNum != i)
            continue;
        if (aWeapons[W_MODEL][0])
            SetHookChainArg(2, ATYPE_STRING, aWeapons[W_MODEL]);
        break;
    }
    return HC_CONTINUE;
}
Same error, marked which line, with "this ->"
PHP Code:
public CBasePlayerWeapon_DefaultDeploy(pWeaponviewModel[], weaponModel[], animanimExt[], skiplocal)
{
    if (
get_entvar(pWeaponvar_impulse) != 0)
        return 
HC_CONTINUE;
    new 
iId get_member(pWeaponm_iId);
this ->    new iNum g_iPlayerSkins[get_member(pWeaponm_pPlayer)][iId];
    if (
iNum == -|| iNum >= g_iWeaponSkinsNum)
        return 
HC_CONTINUE;

    for (new 
iaWeapons[WEAPON_DATA]; g_iWeaponSkinsNumi++)
    {
        
ArrayGetArray(g_aWeaponSkinsiaWeapons);
        if (
aWeapons[WEAPON_ID] != iId)
            continue;
        if (
iNum != i)
            continue;
        if (
aWeapons[V_MODEL][0])
            
SetHookChainArg(2ATYPE_STRINGaWeapons[V_MODEL]);
        if (
aWeapons[P_MODEL][0])
            
SetHookChainArg(3ATYPE_STRINGaWeapons[P_MODEL]);
        break;
    }
    return 
HC_CONTINUE;



PHP Code:
public CWeaponBox_SetModel(pWeaponBox, const szModel[])
{
    new 
pWeapon UTIL_GetWeaponBoxWeapon(pWeaponBox);
    if (
pWeapon == NULLENT)
        return 
HC_CONTINUE;
    if (
get_entvar(pWeaponvar_impulse) != 0)
        return 
HC_CONTINUE;
    new 
iId get_member(pWeaponm_iId);
this ->    new iNum g_iPlayerSkins[get_entvar(pWeaponBoxvar_owner)][iId];
    if (
iNum == -|| iNum >= g_iWeaponSkinsNum)
        return 
HC_CONTINUE;

    for (new 
iaWeapons[WEAPON_DATA]; g_iWeaponSkinsNumi++)
    {
        
ArrayGetArray(g_aWeaponSkinsiaWeapons);
        if (
aWeapons[WEAPON_ID] != iId)
            continue;
        if (
iNum != i)
            continue;
        if (
aWeapons[W_MODEL][0])
            
SetHookChainArg(2ATYPE_STRINGaWeapons[W_MODEL]);
        break;
    }
    return 
HC_CONTINUE;


Last edited by JoneM; 10-24-2023 at 02:57. Reason: edit another line
JoneM is offline
Reply



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 15:37.


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