PDA

View Full Version : Array out of Bonds


Shaheen
16/08/2017, 08:42 AM
Hi,
I have got an error

Debug :

[debug] Run time error 4: "Array index out of bounds"
[debug] Accessing element at negative index -1
[debug] AMX backtrace:
[debug] #0 00290fa4 in public cmd_stats (0, 2752580) from CCNR.amx
[debug] #1 002905ac in public cmd_stats (0, 2741220) from CCNR.amx
[debug] #2 native CallLocalFunction () from samp-server.exe
[debug] #3 0003eeb0 in public OnPlayerCommandText (0, 2741192) from CCNR.amx


Stats Command

COMMAND:stats(playerid, params[]) //
{
new msg[1200];
new msg3[200];
new otherID, gID;
if(sscanf(params, "u", otherID))
{
format(msg, sizeof(msg), "%d", playerid);
cmd_stats(playerid, msg);
}
else
{
if(!isConnected(otherID))
{
if(Player[playerid][english])
//Server(playerid, "That player isn't logged in!.");
SendClientMessage(playerid,COLOR_RED,"The requested player is not connected.");
else
Server(playerid, "Player tidak login.");
return 1;
}
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nKills : "CHAT_YELLOW"%d", msg, Player[otherID][playerKills]);
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nDeaths : "CHAT_YELLOW"%d", msg, Player[otherID][playerDeaths]);
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nXP : "CHAT_YELLOW"%d", msg, Player[otherID][playerXP]);
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nScore : "CHAT_YELLOW"%d", msg, Player[otherID][playerScore]);
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nMoney : "CHAT_YELLOW"%s", msg, FormatNumber(Player[otherID][playerMoney]));
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nRob : "CHAT_YELLOW"%d", msg, Player[otherID][playerRob]);
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nWanted Level : "CHAT_YELLOW"%d", msg, Player[otherID][playerWanted]);
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nPilot Missions : "CHAT_YELLOW"%d", msg, Player[otherID][missions]);
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nDelivery Missions : "CHAT_YELLOW"%d", msg, Player[otherID][delivery]);
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nTaxi Missions : "CHAT_YELLOW"%d", msg, Player[otherID][taxi]);
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nBus Missions : "CHAT_YELLOW"%d", msg, Player[otherID][bus]);
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nPlayer Vehicles : "CHAT_YELLOW"%d", msg, countplayerVeh(otherID));
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nVIP : ", msg);
if(Player[otherID][vipLevel] > 0)
{
format(msg, sizeof(msg), "%s"CHAT_YELLOW"Yes", msg);
}
else
{
format(msg, sizeof(msg), "%s"CHAT_RED"No", msg);
}
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nJailed : ", msg);
if(Player[otherID][isJailed])
{
format(msg, sizeof(msg), "%s"CHAT_YELLOW"Yes", msg);
}
else
{
format(msg, sizeof(msg), "%s"CHAT_RED"No", msg);
}
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nAFK : ", msg);
if(Player[otherID][paused])
{
format(msg, sizeof(msg), "%s"CHAT_YELLOW"Yes", msg);
}
else
{
format(msg, sizeof(msg), "%s"CHAT_RED"No", msg);
}
format(msg, sizeof(msg), "%s"CHAT_WHITE"\nGang : ", msg);
if(inGang(otherID))
{
gID = findGang(otherID);
format(msg, sizeof(msg), "%s{%s}%s", msg, Gang[gID][gangColor], Gang[gID][gangName]);
}
else
{
format(msg, sizeof(msg), "%s"CHAT_RED"NO GANG", msg);
}
format(msg3, sizeof(msg3), "Viewing %s(%d)'s Statistics", GetName(otherID), playerid);
//ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, msg3 , msg, "Close", "");
}
ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, msg3 , msg, "Done", "");
return 1;
}

Thnx in Advance :)

OneDay
16/08/2017, 09:18 AM
Use -d3 for line number.

Shaheen
16/08/2017, 02:50 PM
actually i dont know about this feature.
i have ******d it but could not find it.
it will be sweet if u could have given me a link..

thnx

Misiur
16/08/2017, 02:54 PM
https://github.com/Zeex/samp-plugin-crashdetect/wiki/Compiling-scripts-with-debug-info

Shaheen
16/08/2017, 03:21 PM
Not working with it
any other solutions ?

oMa37
16/08/2017, 03:25 PM
It won't work with it, but It will show you where is the exact line that cause this array out of bounds.
Could you show us the new debugs after you compiled with -d3?

denNorske
16/08/2017, 05:10 PM
Hello Shaheen

Looking at the code, it's obvious that there's a value that is -1 when you access it.

Try to find your pawn config file (settings.ini), and add -d3 into it in the arguments. This will add debug level 3 and most likely give you a line number to work from.

Here is a picture
https://image.prntscr.com/image/cjYN-j4_RTWOFNPLkJ3FeA.png



If this wasn't / isn't working correctly, you'll need to debug the variables manually and print the values to the chat/log.

With a good text editor this is done quickly :)