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

Run time error 4: index out of bounds


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Snitch
Veteran Member
Join Date: Sep 2013
Location: Kazakhstan
Old 02-11-2017 , 04:19   Run time error 4: index out of bounds
Reply With Quote #1

Code:
Run time error 4: index out of bounds 
menuitem_callbackc
Code:
public menuitem_callbackc( id, menu, item )
{
    if( !g_PlayerSkins[id][ Player[ id ][ PLAYER_SKIN ] ] )
    {
        if( Skin_Info[ item ][ SKIN_KNIFE ] != -1 && !g_PlayerKnives[id][Skin_Info[ item ][ SKIN_KNIFE ]] )
        {
            return ITEM_DISABLED;
        }
        else if(!CheckSkin(id, item))
        {
            return ITEM_DISABLED;
        }
    }
    return ITEM_IGNORE;
}
wat wrong? i did a check != -1
__________________
Қазақстан Республикасы
Snitch is offline
Send a message via Skype™ to Snitch
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-11-2017 , 05:36   Re: Run time error 4: index out of bounds
Reply With Quote #2

We can't help without see what this Skin_Info and g_PlayerKnives means. This error happens because the array's size is less than that check. Show us how you defined they.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 02-11-2017 at 05:38.
EFFx is offline
Snitch
Veteran Member
Join Date: Sep 2013
Location: Kazakhstan
Old 02-11-2017 , 06:14   Re: Run time error 4: index out of bounds
Reply With Quote #3

Code:
new g_PlayerKnives[ MAX_PLAYERS + 1 ][ enumKnifes ];
Code:
enum _:enumKnifes
{
    KNIFE_1
}
Code:
new const Skin_Info[ enumSkins ][ enumSkinInfo ] =
{
    { 0, 0, 0, -1, 3 }
    /*{ 5, 2, 2, KNIFE_5, KNIFE_5 },
    { 10, 3, 3, KNIFE_9, KNIFE_9 },
    { 10, 3, 3, KNIFE_15, KNIFE_15 },*/
}
i enabled only skin 1, other no maybe error come from here?
__________________
Қазақстан Республикасы
Snitch is offline
Send a message via Skype™ to Snitch
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 02-11-2017 , 19:27   Re: Run time error 4: index out of bounds
Reply With Quote #4

The problem is not that "Skin_Info[ item ][ SKIN_KNIFE ]" is -1. It is that "item", id, the value of Player[] or Skin_Info[] is negative or larger than the array size.

How to debug your code in 5 minutes:
Print everything.
Code:
public menuitem_callbackc( id, menu, item ) { server_print("menuitem_callbackc(%d, %d, %d) called", id, menu, item);
If that doesn't reveal a problem, you add more messages.
Code:
server_print("Player[id][PLAYER_SKIN]: %d", Player[ id ][ PLAYER_SKIN ]) server_print("g_PlayerSkins[id][...]: %d", g_PlayerSkins[id][ Player[ id ][ PLAYER_SKIN ] ]) server_print("Skin_Info[item][SKIN_KNIFE]: %d", Skin_Info[ item ][ SKIN_KNIFE ]) server_print("g_PlayerKnives[id][...]: %d", g_PlayerKnives[id][Skin_Info[ item ][ SKIN_KNIFE ]])
One of these messages will show an obvious error which you will be able to correct.

If you are still unsure, post the result of those messages here.
__________________

Last edited by Black Rose; 02-11-2017 at 19:28.
Black Rose is offline
Snitch
Veteran Member
Join Date: Sep 2013
Location: Kazakhstan
Old 02-12-2017 , 08:07   Re: Run time error 4: index out of bounds
Reply With Quote #5

@Black Rose thank you. it helped

now i have new error:
Quote:
formatted incorrectly - parameter 8 (total 7)
Run time error 25: parameter error
Code:
stock ColorPrint( const index, const string[], any:... )
{
    new szMsg[ 191 ], Players[ 32 ], PNum = 1;
    
    static iLen; iLen = formatex( szMsg, charsmax( szMsg ), "^4[Joiues]^1 ");
    
    vformat( szMsg[ iLen ], charsmax( szMsg ) - iLen, string, 3 );
    
    if ( index )
        Players[ 0 ] = index;
    
    else
        get_players( Players, PNum, "ch" );
    
    for ( new i; i < PNum; i++ )
    {
        if( is_user_connected( Players[ i ] ) )
        {
            message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, Players[ i ] );
            
            write_byte( Players[ i ] );
            
            write_string( szMsg );
            
            message_end( );
        }
    }
    
    return 1;
}
and here same error:
Code:
GetPosition(Client)
{
    static Position, Size, SteamID[32]
    for(Position = 0, Size = ArraySize(g_SteamID); Position < Size; Position++)
    {
        ArrayGetString(g_SteamID, Position, SteamID, 31) // here
        
        if(equal(SteamID, g_Data[Client][DATA_STEAMID]))
        return Position + 1
    }
    
    return 0
}
__________________
Қазақстан Республикасы
Snitch is offline
Send a message via Skype™ to Snitch
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 02-12-2017 , 08:28   Re: Run time error 4: index out of bounds
Reply With Quote #6

Most likely you have a line with ColorPrint() where you don't have the same number of format placeholders (%d, %i, %f, %c, %s, %x, %a whatever) and arguments following.
Check out the line that the debug message is pointing at.

And just as a side note, use charsmax() instead of manually entering 31 when working with strings.
__________________

Last edited by Black Rose; 02-12-2017 at 08:28.
Black Rose is offline
Snitch
Veteran Member
Join Date: Sep 2013
Location: Kazakhstan
Old 02-12-2017 , 09:06   Re: Run time error 4: index out of bounds
Reply With Quote #7

Quote:
Originally Posted by Black Rose View Post
Most likely you have a line with ColorPrint() where you don't have the same number of format placeholders (%d, %i, %f, %c, %s, %x, %a whatever) and arguments following.
Check out the line that the debug message is pointing at.

And just as a side note, use charsmax() instead of manually entering 31 when working with strings.
mhm.

ArrayGetString(g_SteamID, Position, charsmax (SteamID))?

- debug message is pointing at.
its the stock of colorprint
__________________
Қазақстан Республикасы

Last edited by Snitch; 02-12-2017 at 09:08.
Snitch is offline
Send a message via Skype™ to Snitch
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 02-12-2017 , 10:52   Re: Run time error 4: index out of bounds
Reply With Quote #8

The debug usually points to several things.

Here's an example.

Code:
#include <amxmodx> public plugin_init() {     register_plugin("Test Plugin 1", "1.0", "[ --{-@ ]");         test("%d, %d", 1); } test(const fmt[], any:...) {     new text[128];     vformat(text, charsmax(text), fmt, 2); }

Code:
L 02/12/2017 - 16:49:22: String formatted incorrectly - parameter 3 (total 2)
L 02/12/2017 - 16:49:22: [AMXX] Displaying debug trace (plugin "test1.amxx")
L 02/12/2017 - 16:49:22: [AMXX] Run time error 25: parameter error
L 02/12/2017 - 16:49:22: [AMXX]    [0] test1.sma::test (line 11)
L 02/12/2017 - 16:49:22: [AMXX]    [1] test1.sma::plugin_init (line 6)
As you can see the error message is the same.
It points to line 11 and line 6. Line 11 is where the error occurs but the cause of the problem is at line 6 where I have not supplied enough arguments for the format.
__________________
Black Rose is offline
Snitch
Veteran Member
Join Date: Sep 2013
Location: Kazakhstan
Old 02-12-2017 , 11:39   Re: Run time error 4: index out of bounds
Reply With Quote #9

@Black_Rose
ok i think the error come from ColorPrint, i will try client_print_color

and can u example about charsmax how
Quote:
ArrayGetString(g_SteamID, Position, charsmax (SteamID))
? give me error
__________________
Қазақстан Республикасы
Snitch is offline
Send a message via Skype™ to Snitch
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 02-12-2017 , 15:52   Re: Run time error 4: index out of bounds
Reply With Quote #10

You're missing my point. The function is not the problem. It's how you used it. If you change to client_print_color() you will have the same problem.

You are right, but you just missed to enter SteamID before charsmax(SteamID).
__________________
Black Rose 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 06:23.


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