AMX "Array index out of bounds"
#1

I don't really know whats happening seen as this is working in one of my other scripts. It seems to be the loop what is causing the problem as stated in the LOG

Note: the area what is causing the code as been marked. The Log has also been provided.
Код:
[00:14:35] [debug] Run time error 4: "Array index out of bounds"
[00:14:35] [debug]  Accessing element at index 12 past array upper bound 11
[00:14:35] [debug] AMX backtrace:
[00:14:35] [debug] #0 00029f04 in ?? (0, 0) from rp.amx
[00:14:35] [debug] #1 00029c14 in public OpenInventory (0) from rp.amx
[00:14:35] [debug] #2 0002a4ac in public cmd_inv (0, 4417524) from rp.amx
[00:14:35] [debug] #3 native CallLocalFunction () from samp-server.exe
[00:14:35] [debug] #4 00008838 in public OnPlayerCommandText (0, 4417504) from rp.amx
pawn Код:
enum e_PreviewOffsets {
    e_PreviewModel,
    Float:e_PreviewX,
    Float:e_PreviewY,
    Float:e_PreviewZ
};
static const g_aPreviewOffsets[][e_PreviewOffsets] =
{
    {18875, 90.0, 180.0, 0.0},
    {2703, -105.0, 0.0, -15.0},
    {2702, 90.0, 90.0, 0.0},
    {2814, -90.0, 0.0, -90.0},
    {2768, -15.0, 0.0, -160.0},
    {19142, -20.0, -90.0, 0.0},
    {19166, -90.0, 0.0, -90.0},
    {1581, 0.0, 0.0, 180.0},
    {2958, -10.0, -15.0, 0.0},
    {18634, 90.0, 90.0, 0.0},
    {2043, 0.0, 0.0, 90.0},
    {1484, -15.0, 30.0, 0.0},
    {2226, 0.0, 0.0, 180.0}
};


stock Inventory_Open(playerid, targetid = INVALID_PLAYER_ID)
{
    printf("STARTING INVENTORY OPEN");

   
    if (targetid == INVALID_PLAYER_ID)
        targetid = playerid;


    for(new i = 0; i < 12; i ++)
    {
        if(InventoryData[targetid][i][itemExists])
        {
            PlayerTextDrawSetPreviewModel(playerid, CharacterInventory[playerid][i], InventoryData[targetid][i][itemModel]);

        } else {
            PlayerTextDrawSetPreviewModel(playerid, CharacterInventory[playerid][i], 19300);
        }

/* THIS AREA CAUSES THE AMX ERROR
        for (new oj = 0; oj < sizeof(g_aPreviewOffsets); oj ++)
        {
            if (g_aPreviewOffsets[oj][e_PreviewModel] == InventoryData[targetid][oj][itemModel])
            {
                PlayerTextDrawSetPreviewRot(playerid, CharacterInventory[playerid][i], g_aPreviewOffsets[oj][e_PreviewX], g_aPreviewOffsets[oj][e_PreviewY], g_aPreviewOffsets[oj][e_PreviewZ]);
            }
        }  
*/

    }


    printf("SETTING STRINGS");

    if (targetid == playerid)
    {
        PlayerTextDrawSetString(playerid, CharacterInventory[playerid][1], "My Inventory");
    }
    else
    {
        PlayerTextDrawSetString(playerid, CharacterInventory[playerid][1], "Player Inventory");
    }

    printf("SETTING PREVIEW MODELS");
    PlayerTextDrawSetPreviewModel(playerid, CharacterInventory[playerid][17], CharacterInformation[targetid][CHAR(targetid)][CharacterSkin]);
    PlayerTextDrawSetPreviewModel(playerid, CharacterInventory[playerid][17], 19300);
   
    /*
    if (2 <= GetPlayerWeapon(targetid) <= 46)
        PlayerTextDrawSetPreviewModel(playerid, CharacterInterface[playerid][CharacterInventory][], GetWeaponModelID(GetPlayerWeapon(targetid)));
    */


    printf("SHOWING TEXTDRAWS");
    for (new i = 0; i < 19; i ++) {
        PlayerTextDrawShow(playerid, CharacterInventory[playerid][i]);
    }
    printf("STOPPING SELECTION");
    SelectTextDraw(playerid, -1);
    printf("FINISHED");
    return true;
}
Reply
#2

Ive recently had a similar strange bug with enums and undefined size arrays.
IIRC it was a official bug of the used pawn version, undefined array sizes in multidimensional arrays arent reliable. Instead set the size of g_aPreviewOffsets to 13 manually. Some small extra amount of work when updating it, but at least it works
Reply
#3

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
Ive recently had a similar strange bug with enums and undefined size arrays.
IIRC it was a official bug of the used pawn version, undefined array sizes in multidimensional arrays arent reliable. Instead set the size of g_aPreviewOffsets to 13 manually. Some small extra amount of work when updating it, but at least it works
Thanks for your swifty reply Mauzen, the only thing is when using '13' in the g_aPreviewOffsets[13][enum] it'll still send the amx error (http://prntscr.com/5bkegs), but it does the same thing using that and i < 13 in the loop.

Note: Heading off to sleep (its 00:44 here), I'll check tomorrow.
Reply
#4

Ah okay. Try using just "new" instead of the "static const" definition. I cant explain why this could cause this problem, but it probably does as this is the only "unusual" thing left with that code. You probably dont get any benefits from using them anyways in this case.
Reply
#5

Well that didn't fix the issue, I'm going to re-do the textdraws as-well as the system to go with it to cope with all the new stuff in the script.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)