another backtrace
#1

Hello! I found this recently:

PHP Code:
[18:09:34] [debugRun time error 4"Array index out of bounds"
[18:09:34] [debug]  Attempted to read/write array element at negative index -1
[18:09:34] [debugAMX backtrace:
[
18:09:34] [debug#0 00042230 in public Iter_OnPlayerDisconnect (playerid=1, reason=0) at C:\Users\ert\OneDrive\Desktop\game\gamemodes\game.pwn:890
[18:09:34] [debug#1 native CallLocalFunction () in server
[18:09:34] [debug#2 00038a38 in public SSCANF_OnPlayerDisconnect (playerid=1, reason=0) at C:\Users\ert\OneDrive\Desktop\game\pawno\include\foreach.inc:833
[18:09:34] [debug#3 00031860 in public WC_OnPlayerDisconnect (playerid=1, reason=0) at C:\Users\ert\OneDrive\Desktop\game\pawno\include\sscanf2.inc:266
[18:09:34] [debug#4 00014b98 in public FIXES_OnPlayerDisconnect (1, 0)  at C:\Users\ert\OneDrive\Desktop\game\pawno\include\weapon-config.inc:2243
[18:09:34] [debug#5 00004960 in public OnPlayerDisconnect (playerid=1, reason=0) at C:\Users\ert\OneDrive\Desktop\game\pawno\include\fixes.inc:6522 
This happens if a player disconnects in the middle of a duel. Line:

PHP Code:
format(strsizeof(str), "%s abandoned the server in the mid of a duel vs %s. %s is the winner. [%.0f health and %.0f armour]"GetName(playerid), GetName(id), GetName(id), healtharmour); 
OnPlayerDisconnect:

PHP Code:
public OnPlayerDisconnect(playeridreason)
{
   
//another checks...
    
if(PlayerInfo[playerid][inDuel] == 1)
    {
        new 
id PlayerInfo[playerid][Duelingto], Float:healthFloat:armourstr[124];
        
GetPlayerHealth(idhealth);
        
GetPlayerArmour(idarmour);
        
ResetPlayerWeapons(id);
        
SetPlayerVirtualWorld(id0);
        
SetPlayerInterior(id0);
        
SetPlayerHealth(id100);
        
SpawnPlayer(id);
        
format(strsizeof(str), "%s abandoned the server in the mid of a duel vs %s. %s is the winner. [%.0f health and %.0f armour]"GetName(playerid), GetName(id), GetName(id), healtharmour);
        
SendClientMessageToAll(CDUELstr);
        
PlayerInfo[id][Duelingto] = -1;
        
PlayerInfo[id][Maker] = -1;
        
PlayerInfo[id][Opponent] = -1;
        
PlayerInfo[playerid][LoseDuels] ++;
        
PlayerInfo[id][WinDuels] ++;
    }
   
// another checks etc
   
return 1;

The message is sent correctly to the other player and runs well the code but i founded this in the log
Reply
#2

Which line is 890? The issue could come from the fact that -if i'm not mistaken-, unless you store the player's name before he disconnects, GetName can't access the player's name anymore as he disconnected. Although this would be weird assuming that the message is sent correctly.
Reply
#3

Quote:
Originally Posted by Adamoneoone
View Post
Which line is 890? The issue could come from the fact that -if i'm not mistaken-, unless you store the player's name before he disconnects, GetName can't access the player's name anymore as he disconnected. Although this would be weird assuming that the message is sent correctly.
The line is the one I put in:

PHP Code:
format(strsizeof(str), "%s abandoned the server in the mid of a duel vs %s. %s is the winner. [%.0f health and %.0f armour]"GetName(playerid), GetName(id), GetName(id), healtharmour); 
I think it's the GetName(playerid) but it's sent correctly anyway. So I don't know why I get that. I don't save the names in a variable, instead I use the GetName().
Reply
#4

Bump
Reply
#5

Are you resetting the PlayerInfo array when the player disconnects? If so, make sure to do the duel check before you reset it, otherwise I assume you set the value to -1 before you actually do your check, so "id" will always be -1 which isn't a valid player ID.

You also have a typo in your parameters, while it's unrelated to your problem, you gotta figure it out.
Reply
#6

Since arrays start from 0, -1 looks like an arbitrary value you give to it.

Post OnPlayerDisconnect entirely, maybe we can help.
Reply
#7

PHP Code:
        PlayerInfo[id][Duelingto] = -1;
        
PlayerInfo[id][Maker] = -1;
        
PlayerInfo[id][Opponent] = -1;
        
PlayerInfo[playerid][LoseDuels] ++;
        
PlayerInfo[id][WinDuels] ++; 
We can't see your whole code, but I'd presuming these would need to be in the above bit no?

PHP Code:
        PlayerInfo[playerid][inDuel] = 0;
        
PlayerInfo[id][inDuel] = 0
Reply
#8

Quote:
Originally Posted by Variable™
View Post
Are you resetting the PlayerInfo array when the player disconnects? If so, make sure to do the duel check before you reset it, otherwise I assume you set the value to -1 before you actually do your check, so "id" will always be -1 which isn't a valid player ID.

You also have a typo in your parameters, while it's unrelated to your problem, you gotta figure it out.
I checked and I don't see anything wrong, could you tell me a clue? I will post the code.

Quote:
Originally Posted by v1k1nG
View Post
Since arrays start from 0, -1 looks like an arbitrary value you give to it.

Post OnPlayerDisconnect entirely, maybe we can help.
Quote:
Originally Posted by ItsRobinson
View Post
PHP Code:
        PlayerInfo[id][Duelingto] = -1;
        
PlayerInfo[id][Maker] = -1;
        
PlayerInfo[id][Opponent] = -1;
        
PlayerInfo[playerid][LoseDuels] ++;
        
PlayerInfo[id][WinDuels] ++; 
We can't see your whole code, but I'd presuming these would need to be in the above bit no?

PHP Code:
        PlayerInfo[playerid][inDuel] = 0;
        
PlayerInfo[id][inDuel] = 0


PHP Code:
public OnPlayerDisconnect(playeridreason)
{
    if(
gTeam[playerid][TEAMATT] == 1)
    {
        
CountAtt --;
    }
    if(
gTeam[playerid][TEAMDEF] == 1)
    {
        
CountDef --;
    }
    if(
PlayerInfo[playerid][inDuel] == 1)
    {
        new 
id PlayerInfo[playerid][Duelingto], Float:healthFloat:armourstr[124];
        
GetPlayerHealth(idhealth);
        
GetPlayerArmour(idarmour);
        
ResetPlayerWeapons(id);
        
SetPlayerVirtualWorld(id0);
        
SetPlayerInterior(id0);
        
SetPlayerHealth(id100);
        
SpawnPlayer(id);
        
format(strsizeof(str), "%s abandoned the server in the mid of a duel vs %s. %s is the winner. [%.0f health and %.0f armour]"GetName(playerid), GetName(id), GetName(id), healtharmour); 
        
SendClientMessageToAll(CDUELstr);
        
PlayerInfo[id][Duelingto] = -1;
        
PlayerInfo[id][Maker] = -1;
        
PlayerInfo[id][Opponent] = -1;
        
PlayerInfo[playerid][LoseDuels] ++;
        
PlayerInfo[id][WinDuels] ++;
    }
    if(
PlayerInfo[playerid][Inviter] == 1)
    {
        new 
id PlayerInfo[playerid][Inviter], str[124];
        
PlayerInfo[id][Invited] = 0;
        
KillTimer(InviteTimer[id]);
        
format(strsizeof(str), "%s disconnected in the mid of the invite. The invite is cancelled."GetName(playerid));
        
SendClientMessage(idCDUELstr);
    }
    if(
PlayerInfo[playerid][Invited] == 1)
    {
        new 
id PlayerInfo[playerid][Invited], str[124];
        
PlayerInfo[id][Inviter] = 0;
        
KillTimer(InviteTimer[id]);
        
format(strsizeof(str), "%s disconnected in the mid of the invite. The invite is cancelled."GetName(playerid));
        
SendClientMessage(idCDUELstr);
    }
    if(
SniperGame[playerid] == 1)
    {
        new 
str[124];
        
countsniper --;
        
format(strsizeof(str), "%s disconnected in the mid of sniper game. (%d players)."GetName(playerid), countsniper);
        
SendClientMessageToAll(-1str);
    }
    
    
Saving(playerid);
    
PlayerInfo[playerid][Logged] = 0;
    
PlayerInfo[playerid][pDeaths] = 0;
    
PlayerInfo[playerid][pKills] = 0;
    
PlayerInfo[playerid][Invisible] = 0;
    
PlayerInfo[playerid][God] = 0;
    
PlayerInfo[playerid][PMs] = 0;
    
PlayerInfo[playerid][Muted] = 0;
    
PlayerInfo[playerid][Admin] = 0;
    
PlayerInfo[playerid][Skin] = 0;
    
PlayerInfo[playerid][ATT] = 0;
    
PlayerInfo[playerid][DEF] = 0;
    
PlayerInfo[playerid][DMG] = 0;
    
PlayerInfo[playerid][TotalDMG] = 0;
    
PlayerInfo[playerid][FPSCheck] = 0;
    
PlayerInfo[playerid][FPSKick] = 0;
    
PlayerInfo[playerid][MsKick] = 0;
    
PlayerInfo[playerid][MsCheck] = 0;
    
PlayerInfo[playerid][NetCheck] = 0;
    
PlayerInfo[playerid][RestartSpawn] = 0;
    
PlayerInfo[playerid][WinRounds] = 0;
    
PlayerInfo[playerid][LoseRounds] = 0;
    
PlayerInfo[playerid][Hora] = 0;
    
PlayerInfo[playerid][Clima] = 0;
    
PlayerInfo[playerid][Warns] = 0;
    
PlayerInfo[playerid][Kicks] = 0;
    
PlayerInfo[playerid][Maker] = -1;
    
PlayerInfo[playerid][Opponent] = -1;
    
PlayerInfo[playerid][inDuel] = 0;
    
PlayerInfo[playerid][DuelMap] = 0;
    
PlayerInfo[playerid][DuelPack] = 0;
    
PlayerInfo[playerid][DuelArmour] = 0;
    
PlayerInfo[playerid][WeapDuel] = 0;
    
PlayerInfo[playerid][OnWeap] = 0;
    
PlayerInfo[playerid][Inviter] = 0;
    
PlayerInfo[playerid][Invited] = 0;
    
PlayerInfo[playerid][Duelingto] = -1;
    
PlayerInfo[playerid][WinDuels] = 0;
    
PlayerInfo[playerid][LoseDuels] = 0;
    
PlayerInfo[playerid][Duelos] = 1;
    
PlayerInfo[playerid][Duty] = 1;
    
gTeam[playerid][TEAMATT] = 0;
    
gTeam[playerid][TEAMDEF] = 0;
    
Streaks[playerid] = 0;
    
Voted[playerid] = 0;
    
LastPm[playerid] = -1;
    
onspec[playerid] = -1;
    
SendDeathMessage(INVALID_PLAYER_IDplayerid201);
    
TextDrawHideForPlayer(playeridTextdrawLogo1);
    
TextDrawHideForPlayer(playeridTextdraw2);
    
TextDrawHideForPlayer(playeridTextdrawDMG[playerid]);
    return 
1;

Reply
#9

In your code you are using "id" to refer to the player that this disconnected player was duelling but you are not considering whether the id value is -1 (the value you're resetting it to) or not. You should check if id isn't -1 before continuing with the rest of the related code, because if it is -1 that means that the target player will never be valid, so there's no reason to continue with it.
Reply
#10

Quote:
Originally Posted by Variable™
View Post
In your code you are using "id" to refer to the player that this disconnected player was duelling but you are not considering whether the id value is -1 (the value you're resetting it to) or not. You should check if id isn't -1 before continuing with the rest of the related code, because if it is -1 that means that the target player will never be valid, so there's no reason to continue with it.
Uh, I didn't quite understand, could you give me an example?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)