Run time error 4: "Array index out of bounds"
#1

Hi there!

I have recently noticed that there's a run time error with my script, do any of you please know how to solve it..?
I can't figure out what might be the issue here.. as as well I don't receive any error on compilation.
Код:
[debug] Run time error 4: "Array index out of bounds"
[14:07:03] [debug]  Accessing element at index 61 past array upper bound 59
[14:07:03] [debug] AMX backtrace:
[14:07:03] [debug] #0 0001d50c in public OnPlayerSpawn () at GM.pwn:861
pawn Код:
#undef MAX_PLAYERS
    #define MAX_PLAYERS         (60)

// top of the script
new spawn[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
     spawn[playerid] = 0;
     return 1;
}

public OnPlayerSpawn(playerid)
{
     // Sometimes returns playerid -> 61(?)
     if(!spawn[playerid]) // is first player spawn
     {
          // Do stuff here if that's the first time the player spawning since he connected
          spawn[playerid] = 1; // set spawn var to 1 to ignore any other spawn -> line 861
     }
     return 1;
}
Reply
#2

MAX_PLAYERS might be the problem. Increase the number there.
Reply
#3

Well.. I have a lot more of variables than that and all they all use MAX_PLAYERS (60).. I honestly doubt that this might be the solution.
Reply
#4

Quote:
Originally Posted by Loot
Посмотреть сообщение
Well.. I have a lot more of variables than that and all they all use MAX_PLAYERS (60).. I honestly doubt that this might be the solution.
How many slots does your server have?
Reply
#5

change your MAX_PLAYERS Your maximum of players amount
pawn Код:
#define MAX_PLAYERS 500
Reply
#6

Quote:
Originally Posted by InfiniTy.
Посмотреть сообщение
How many slots does your server have?
60.
Quote:
Originally Posted by Aliassassin123456
Посмотреть сообщение
change your MAX_PLAYERS Your maximum of players amount
pawn Код:
#define MAX_PLAYERS 500
Are you serious?
Reply
#7

There must be an internal error in your script regarding callback hooking. Do you have any includes that hook the "OnPlayerSpawn" callback?
Reply
#8

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
There must be an internal error in your script regarding callback hooking. Do you have any includes that hook the "OnPlayerSpawn" callback?
I guess not, just checked all attached includes.
I haven't hooked anything at the GM however.


- That's very weird since it's the only variable that triggers crashdetect...
Reply
#9

Just put a print there and check the value of playerid, also recheck that maxplayers is set to 60 in server.cfg
Reply
#10

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Just put a print there and check the value of playerid, also recheck that maxplayers is set to 60 in server.cfg
Looks like the value is 61 for some weird reason... And maxplayers is 60 as needed.
EDIT: I had an issue with a specific function that bugged everything.. -> firstSpawn variable wasn't the issue as I thought it was (according to crashdetect).

The problem has been fixed! Much appreciated!

pawn Код:
#define MAX_USER_NAMES   (1)
#define MAX_NAME_LENGTH  (10)

static userNamesX[MAX_USER_NAMES][MAX_NAME_LENGTH] =
{
    {"Exam_Test"}
};

stock IsUsernameX(playerid)
{
    new name[MAX_NAME_LENGTH];
    GetPlayerName(playerid, name, sizeof(name));
    for(new i; i < MAX_USER_NAMES; i++)
    {
        if(!strcmp(name, userNamesX[i], false))
        {
            return 1;
        }
    }
    return 0;
}
public OnPlayerSpawn(playerid)
{
    // Usage ...
    if(IsUsernameX(playerid))
    {
        // ...
    }
    // Probably by this time (playerid = 61)
    // From here and on playerid was equal to 61
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)