Run time error 4: "Array index out of bounds" -
Loot - 19.11.2013
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;
}
Re: Run time error 4: "Array index out of bounds" -
InfiniTy. - 19.11.2013
MAX_PLAYERS might be the problem. Increase the number there.
Re: Run time error 4: "Array index out of bounds" -
Loot - 19.11.2013
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.
Re: Run time error 4: "Array index out of bounds" -
InfiniTy. - 19.11.2013
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?
Re: Run time error 4: "Array index out of bounds" -
Aliassassin123456 - 19.11.2013
change your MAX_PLAYERS Your maximum of players amount
Re: Run time error 4: "Array index out of bounds" -
Loot - 19.11.2013
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
|
Are you serious?
Re: Run time error 4: "Array index out of bounds" - Emmet_ - 19.11.2013
There must be an internal error in your script regarding callback hooking. Do you have any includes that hook the "
OnPlayerSpawn" callback?
Re: Run time error 4: "Array index out of bounds" -
Loot - 19.11.2013
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...
AW: Run time error 4: "Array index out of bounds" -
Nero_3D - 19.11.2013
Just put a print there and check the value of playerid, also recheck that maxplayers is set to 60 in server.cfg
Re: AW: Run time error 4: "Array index out of bounds" -
Loot - 19.11.2013
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;
}