Accessing element at index 65535
#1

Hello everybody,
I spawned in my server (I have crashdetect plugin) and got this in console:
Код:
[20:02:53] [debug] Run time error 4: "Array index out of bounds"
[20:02:53] [debug]  Accessing element at index 65535 past array upper bound 499
[20:02:53] [debug] AMX backtrace:
[20:02:53] [debug] #0 0001f114 in ?? (0x00000000, 0x0000ffff, 0x3f1f3b54, 0x4017dbf5) from Island.amx
[20:02:53] [debug] #1 00049f60 in ?? (0x00000000) from Island.amx
[20:02:53] [debug] #2 000ce334 in ?? (0x00000000) from Island.amx
[20:02:53] [debug] #3 000189e4 in public FIXES_OnPlayerSpawn (0x00000000) from Island.amx
[20:02:53] [debug] #4 00004c14 in public OnPlayerSpawn (0x00000000) from Island.amx
Maybe some of you are familiar with this error and know why it happens?
Reply
#2

65535 means INVALID_PLAYER_ID, you got somewhere
new array_name[MAX_PLAYERS]; // 500 = 0 - 499

array_name[65535]

compile with -d3 flag and show again info

https://github.com/Zeex/samp-plugin-...ith-debug-info
Reply
#3

Quote:
Originally Posted by Jefff
Посмотреть сообщение
65535 means INVALID_PLAYER_ID, you got somewhere
new array_name[MAX_PLAYERS]; // 500 = 0 - 499

array_name[65535]

compile with -d3 flag and show again info

https://github.com/Zeex/samp-plugin-...ith-debug-info
Thanks, but it happens randomly, most of the times there is no error..
Reply
#4

Search in OnPlayerSpawn which array can holds INVALID_PLAYER_ID
Reply
#5

It occurring randomly and 65535 is a sure sign that you have a problem somewhere with INVALID_PLAYER_ID or INAVLID_VEHICLE_ID......

Please edit your thread and add your code(OnPlayerSpawn) so that we can help you.Right now we have no clue what is exactly causing it.
Reply
#6

It may happen when to use sscanf and you try to /pm a non-connected player (or use any other command which accepts a playerid).
Trying to /pm me using "/pm xPower blabla" would result in getting INVALID_PLAYER_ID returned by sscanf to indicate no player was found with that name.

So, right after sscanf, ALWAYS check if the returned playerid is below MAX_PLAYERS.
If the value is valid, continue the command.
If it's invalid, exit the command immediately using a "return SendClientMessage(playerid, -1, "That player isn't online");".

If you just use the value returned to access an array (PlayerData array for example), you'll get that error.

pawn Код:
// Freeze a player
COMMAND:freeze(playerid, params[])
{
    // If the player has an insufficient admin-level (he needs level 1), exit the command
    if (APlayerData[playerid][AdminLevel] < 1) return SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}Only admins level 1 and higher can use this command");

    // Setup local variables
    new Msg[128], OtherPlayer, Duration;

    // Split the parameters
    if (sscanf(params, "ui", OtherPlayer, Duration)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/freeze <OtherPlayer> <Duration>\"");

    // If the other player has an invalid ID (sscanf returns 65535 as playerid if the player cannot be found), exit the command
    if (OtherPlayer >= MAX_PLAYERS) return SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}That player is not online");
    // If the other player is still in class selection, exit the command
    if (Player_InClassSelection(OtherPlayer) == 1) return SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}That player is still in class-selection and cannot be frozen");
    // If an invalid duration was given (0 or lower), exit the command
    if (Duration <= 0) return SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}Duration must be minimum 1 second");

    // Freeze the given player for the specified duration (store the freezetime and freeze the player)
    APlayerData[OtherPlayer][FreezeTime] = Duration;
    TogglePlayerControllable(OtherPlayer, 0);

    // Let the other player know he has been frozen and by who
    format(Msg, sizeof(Msg), "{FF0000}You've been frozen for {FFFF00}%i{FF0000} seconds by {FFFF00}%s", Duration, APlayerData[playerid][Name]);
    SendClientMessage(OtherPlayer, 0xFFFFFFFF, Msg);
    // Let the admin know who's been frozen
    format(Msg, sizeof(Msg), "{00FF00}You have frozen {FFFF00}%s", APlayerData[OtherPlayer][Name]);
    SendClientMessage(playerid, 0xFFFFFFFF, Msg);
    // Now the global timer takes over to un-freeze him when the timer has reached 0 (also the freeze-time is saved automatically by the global timer)

    // Let the server know that this was a valid command
    return 1;
}
Like this (copy/pasted example from my own script).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)