Crashdetect detected me this :o
#1

Код:
[2014.08.07 <> 22:17:00] [debug] Run time error 4: "Array index out of bounds"
[2014.08.07 <> 22:17:00] [debug]  Accessing element at index 25 past array upper bound 24
[2014.08.07 <> 22:17:00] [debug] AMX backtrace:
[2014.08.07 <> 22:17:00] [debug] #0 00075754 in ?? (0x00000001, 0xff8000ff, 0x002d7d18) from LVG.amx
[2014.08.07 <> 22:17:00] [debug] #1 00075178 in public OnDialogResponse (0x00000000, 0x0000040b, 0x00000001, 0xffffffff, 0x002d3f24) from LVG.amx
As I found out, every function until one is going well. That's that one:
pawn Код:
gInfo[0][gBank] += rksm; // well
GiveMoney(playerid, -rksm); // well
new df[60],sd[60]; // well
format(df,60,"You have successfully put~n~~p~%i ~w~$ to GangBank!",rksm); // well
format(sd,60,"[gang] %s just put %i $ to GangBank!",PlayerName(playerid), rksm); // well
SPMB(playerid, df); // well
printf("%s just put %i $ to GanBank",PlayerName(playerid),rksm); // well
SendMessageToGang(1,COLOR_ORANGE,sd); // CRASH!

// now the stock

stock SendMessageToGang(gangid, color, message[])
{
    for(new i = 0; i <= MAX_PLAYERS; i++)
    {
        if(Gang[i] == gangid)
        {
            SCM(i,color,message);
        }
    }
    return 1;
}
So I'm the only on the server with ID 0 and message is sent to me. WTF?
Reply
#2

pawn Код:
stock SendMessageToGang(gangid, color, message[])
{
    for(new i = 0; i <MAX_PLAYERS; i++)
    {
        if(Gang[i] == gangid)
        {
            SCM(i,color,message);
        }
    }
    return 1;
}
By using (i <= MAX_PLAYERS), you are looping through 501 numbers (0-500) instead of 500 (0-499), making a statement like this (at some point):
pawn Код:
if(Gang[500] == gangid)
Gang[500] is out of bounds, as it goes from Gang[0] to Gang[499], making it crash.
Reply
#3

pawn Код:
#include <a_samp>

// some code

#undef MAX_PLAYERS
#define MAX_PLAYERS 25

// some code

new Gang[MAX_PLAYERS];
My MAX_PLAYERS is 25 slots big. But helped! It works now. Thanks.
Reply
#4

Holly molly. Right. Now sometimes it works perfectly, but sometimes it shows the same thing.... What's happening here?
Reply
#5

Anyone?
Reply
#6

Check IsPlayerConnected maybe? Or use foreach

//and
Код HTML:
<= MAX_PLAYERS
change on
Код HTML:
< MAX_PLAYERS
IDs are from 0 to 24 not 25
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)