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

Solved weird Index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JocAnis
Veteran Member
Join Date: Jun 2010
Old 05-23-2020 , 20:14   weird Index out of bounds
Reply With Quote #1

Hi guys, im getting Index out of bounds, but i cant see any error/warning in the code, could be that a enum problem?

Code:
Code:
enum _:eModels
{
    MODEL_NAME[100],
    MODEL_LOCATION[100],
    MODEL_COST
}
new const ModelItems[][ eModels ] =
{
    { "Default", "gign", 0 },
    { "Agent Smith", "agent", 1000 },
    { "Terminator", "terminator", 1500 }
}
public fwSpawn_Post( id )
{
    if( is_user_bot( id ) || is_user_hltv( id ) )
        return

    if( is_user_alive( id ) )
    {
        set_task( 0.1, "check_model", id + 234 ) //pretty sure set task is not needed, but same error both situations
    }
}
public check_model( task )
{
    new id = task - 234

    if( cs_get_user_team( id ) == CS_TEAM_CT )
    {
        if( g_iModelSelected[ id ] > 0 )
            cs_set_user_model( id, ModelItems[ g_iModelSelected[ id ] ][ MODEL_LOCATION ] ) //this line is giving the warning
    }
    else if( cs_get_user_team( id ) == CS_TEAM_T )
        cs_set_user_model( id, "richtr" )
}
public client_putinserver( id )
{
    g_iModelSelected[ id ] = 0
}
public client_disconnedted( id )
{
    g_iModelSelected[ id ] = 0
}
Thanks in advance
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)

Last edited by JocAnis; 05-23-2020 at 21:25.
JocAnis is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-23-2020 , 20:19   Re: weird Index out of bounds
Reply With Quote #2

Show which line is giving you index out of bounds.

And need to see how you are assigning a value to g_iModelSelected[ id ]

I get no warnings using 1.9
__________________

Last edited by Bugsy; 05-23-2020 at 20:20.
Bugsy is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 05-23-2020 , 20:22   Re: weird Index out of bounds
Reply With Quote #3

this line is giving ONLY ingame warning (on compiling its all ok):
Code:
cs_set_user_model( id, ModelItems[ g_iModelSelected[ id ] ][ MODEL_LOCATION ] )
PS: its assigning model to every player how it should, but also giving a warning in console..wtf
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-23-2020 , 20:24   Re: weird Index out of bounds
Reply With Quote #4

What is an in game warning? I am asking for the run-time error in your plugin which should be in logs.

What version of AMX?
__________________
Bugsy is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 05-23-2020 , 20:26   Re: weird Index out of bounds
Reply With Quote #5

Code:
05/24/2020 - 01:55:04: [AMXX] Displaying debug trace (plugin "model_plugin.amxx", version "1.0")
L 05/24/2020 - 01:55:04: [AMXX] Run time error 4: index out of bounds 
L 05/24/2020 - 01:55:04: [AMXX]    [0] model_plugin.amxx::check_model (line 139)
L 05/24/2020 - 01:55:08: [AMXX] Displaying debug trace (plugin "model_plugin.amxx", version "1.0")
1.8.3 version, first time seeing this
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-23-2020 , 20:28   Re: weird Index out of bounds
Reply With Quote #6

05/24/2020 - 01:55:04: [AMXX] Displaying debug trace (plugin "model_plugin.amxx", version "1.0")
L 05/24/2020 - 01:55:04: [AMXX] Run time error 4: index out of bounds
L 05/24/2020 - 01:55:04: [AMXX] [0] model_plugin.amxx::check_model (line 139)
L 05/24/2020 - 01:55:08: [AMXX] Displaying debug trace (plugin "model_plugin.amxx", version "1.0")

I need that line, and need to see where g_iModelSelected[ id ] is assigned a value
__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-23-2020 , 20:31   Re: weird Index out of bounds
Reply With Quote #7

This is your problem:

cs_set_user_model( id, ModelItems[ g_iModelSelected[ id ] ][ MODEL_LOCATION ] )

g_iModelSelected[ id ] is getting a value assigned to it that is less than 0, or greater than 2.
__________________
Bugsy is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 05-23-2020 , 20:34   Re: weird Index out of bounds
Reply With Quote #8

line 139 is:
Code:
cs_set_user_model( id, ModelItems[ g_iModelSelected[ id ] ][ MODEL_LOCATION ] )
assigned value:
Code:
public model_handle( id, menu, item )
{
    if( item == MENU_EXIT || item == 9 )
    {
        menu_destroy( menu )
        return PLUGIN_HANDLED
    }

    if ( !g_bHaveThatModel[ id ] )
    {
        if( item > 0 && item < 8 )
        {
            if ( ModelItems[ item ][ MODEL_COST ] > get_dr_points( id ) )
            {
                ColorChat(id, RED, "^4[Menu]^1 No points." )
                model_shop( id )
                return PLUGIN_HANDLED;
            }

            set_dr_points( id, -ModelItems[ item ][ MODEL_COST ] )
            g_bHaveThatModel[ id ] |= his_bit( item )
        }
        else if( item == 8 )
        {
            if( ( get_user_flags( id ) & ADMIN_LEVEL_H ) || ( get_user_flags( id ) & ADMIN_LEVEL_G ) )
            {
                ColorChat( id, BLUE, "^4[Menu]^1 VIP Skin^1 !" )
            }
            else
            {
                 ColorChat( id, BLUE, "^4[Menu]^1 You dont have access." )
                 menu_destroy( menu )
                 model_shop( id )
                 return PLUGIN_HANDLED
             }
        }
    }
    g_iModelSelected[ id ] = item //probably you want this, but i dont see a potential error here

    if( is_user_alive( id ) )
    {
        if( cs_get_user_team( id ) == CS_TEAM_CT )
            cs_set_user_model( id, ModelItems[ g_iModelSelected[ id ] ][ MODEL_LOCATION ] ) /assign a model immediately
    }
    menu_destroy( menu )
    model_shop( id )
    return PLUGIN_HANDLED
}
EDIT:
Quote:
Originally Posted by Bugsy View Post
This is your problem:

cs_set_user_model( id, ModelItems[ g_iModelSelected[ id ] ][ MODEL_LOCATION ] )

g_iModelSelected[ id ] is getting a value assigned to it that is less than 0, or greater than 2.
i undestand that in theory, but i dont see how is it assigned to -1 or more than items from ModelItems
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)

Last edited by JocAnis; 05-23-2020 at 20:49.
JocAnis is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-23-2020 , 20:38   Re: weird Index out of bounds
Reply With Quote #9

Need to see how the menu is created
__________________
Bugsy is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 05-23-2020 , 20:48   Re: weird Index out of bounds
Reply With Quote #10

Code:
public model_shop( id )
{
    new menu = menu_create( fmt( "Model Shop^n\dYour Points:\y %d", get_dr_points( id ) ), "model_handle" )

    for( new i; i < sizeof ModelItems - 1; i++ )
    {
        if( i == 0 )
        {
            menu_additem( menu, fmt( "%s\r [ %s ]", ModelItems[ i ][ MODEL_NAME ], g_iModelSelected[ id ] == 0 ? "SELECTED":"OWNED" ) )
        }
        else
        {
            if( g_bHaveThisModel[ id ] & his_bit( i ) )
                menu_additem( menu, fmt( "\d%s \r[ %s ]%s", ModelItems[ i ][ MODEL_NAME ], g_iModelSelected[ id ] == i ? "SELECTED":"OWNED", i == sizeof ModelItems - 1 ? "":"" ) )
            else
            {
                menu_additem( menu, fmt( "\w%s \y[ %d points ]%s", ModelItems[ i ][ MODEL_NAME ], ModelItems[ i ][ MODEL_COST ], i == sizeof ModelItems - 1 ? "":""  ) ) 
            }
        }
    }
    if( ( get_user_flags( id ) & ADMIN_LEVEL_H ) || ( get_user_flags( id ) & ADMIN_LEVEL_G ) )
        menu_additem( menu, "\yVIP Skin^n" )
    else
        menu_additem( menu, "\dVIP Skin^n" )

    menu_additem( menu, "Exit", "0" )
    menu_setprop( menu, MPROP_PERPAGE, 0 )

    menu_setprop( menu, MPROP_EXIT, MEXIT_ALL );

    menu_display( id, menu, 0 )
    return PLUGIN_HANDLED
}
EDIT: now i see i got two lines with "":"" lol
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)

Last edited by JocAnis; 05-23-2020 at 20:50.
JocAnis 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 19:08.


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