Textdraw: Array index out of bounds
#1

Simple global textdraw declaration and initialization and checking for clicks on it.

pawn Код:
static Text:AmmunationGlobal[17];

hook OnGameModeInit() {
    // A bunch of textdraws...

    AmmunationGlobal[16] = TextDrawCreate(431.699951, 164.310958, "X");
    TextDrawLetterSize(AmmunationGlobal[16], 0.318331, 1.122961);
    TextDrawTextSize(AmmunationGlobal[16], 9.000000, 9.000000);
    TextDrawAlignment(AmmunationGlobal[16], 2);
    TextDrawColor(AmmunationGlobal[16], -1);
    TextDrawUseBox(AmmunationGlobal[16], 1);
    TextDrawBoxColor(AmmunationGlobal[16], -16776961);
    TextDrawSetShadow(AmmunationGlobal[16], 0);
    TextDrawSetOutline(AmmunationGlobal[16], 0);
    TextDrawBackgroundColor(AmmunationGlobal[16], 255);
    TextDrawFont(AmmunationGlobal[16], 1);
    TextDrawSetProportional(AmmunationGlobal[16], 1);
    TextDrawSetSelectable(AmmunationGlobal[16], true);
}

hook OnPlayerClickTextDraw(playerid, Text:clickedid) {
    if(clickedid == AmmunationGlobal[16]) {
        CancelSelectTextDraw(playerid);
        CloseAmmunationStore(playerid);
    }
    return 0;
}
In fact, everything works fine. I'm getting this from crashdetect, though.
Код:
[00:59:42] [debug] Run time error 4: "Array index out of bounds"
[debug] AMX backtrace:
[debug] #0 00066b14 in ?? (0) from main.amx
[debug] #1 0005f88c in ?? (0) from main.amx
[debug] #2 0006a310 in ?? (0, 22, 0, 0, 8, 0, 22, 0, 0, 0, ... <1073741813 arguments>) from main.amx
[debug] #3 0001a7a4 in public OnPlayerClickTextDraw (0, 22) from main.amx
Why am I getting these?
Reply
#2

PHP код:
hook OnPlayerClickTextDraw(playeridText:clickedid) {
    if(
clickedid == AmmunationGlobal[16]) {
        
CancelSelectTextDraw(playerid);
        
CloseAmmunationStore(playerid);
    }
    return 
0;

You are hooking the function here. Is this the only code you have under "OnPlayerClickTextDraw" ?
Also, it would be worth posting the "CloseAmmunitionStore" function here as well.
Reply
#3

Yes, this is the only code I have under this callback. I'm hooking it because I'm planning to hook it multiple times.

Код:
static CloseAmmunationStore(playerid) {
    HideAmmunationBaseFrame(playerid); //Hide global textdraws
    DestroyAmmunationPTDs(playerid); //Hide and destroy player textdraws
    return 1;
}

static HideAmmunationBaseFrame(playerid) {
    for(new i = 0; i < sizeof(AmmunationGlobal); i++) {
        TextDrawHideForPlayer(playerid, AmmunationGlobal[i]); //comes from static AmmunationGlobal[17]
    }
    return 1;
}

static DestroyAmmunationPTDs(playerid) {
    PlayerTextDrawHide(playerid, ItemPreview[playerid]);
    PlayerTextDrawHide(playerid, WeaponsTab[playerid]);
    PlayerTextDrawHide(playerid, ArmorTab[playerid]);
    for(new i = 0; i < sizeof(Item); i++) { PlayerTextDrawHide(playerid, Item[playerid][i]); }
    PlayerTextDrawHide(playerid, ItemData[playerid]);
    PlayerTextDrawHide(playerid, PurchaseButton[playerid]);
    PlayerTextDrawHide(playerid, ItemAmount[playerid]);

    PlayerTextDrawDestroy(playerid, ItemPreview[playerid]);
    PlayerTextDrawDestroy(playerid, WeaponsTab[playerid]);
    PlayerTextDrawDestroy(playerid, ArmorTab[playerid]);
    for(new i = 0; i < sizeof(Item); i++) { PlayerTextDrawDestroy(playerid, Item[playerid][i]); }
    PlayerTextDrawDestroy(playerid, ItemData[playerid]);
    PlayerTextDrawDestroy(playerid, PurchaseButton[playerid]);
    PlayerTextDrawDestroy(playerid, ItemAmount[playerid]);
    return 1;
}
Reply
#4

Here is likely to be your issue (sorry for late reply)

PHP код:
 for(new 0sizeof(Item); i++) { PlayerTextDrawDestroy(playeridItem[playerid][i]); } 
I actually think the sizeof you do here, get's the [MAX_PLAYERS], and that's why i grows above the array size, because "i" is in the last dimension of the array..

Here is a little explanation how to avoid this: http://forum.sa-mp.com/showpost.php?...6&postcount=15

You just remove the value in the first dimension, and it should look like this:

Quote:

for(new i = 0; i < sizeof(Item[]); i++) { PlayerTextDrawDestroy(playerid, Item[playerid][i]); }

Do the following both places in your code, good luck!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)