Crashdetect
#1

Basically, my server crashes each time inventory function is called through OnDialogResponse, here is what crashdetect.dll says;

Код:
 [debug]  Stack pointer (STK) is 0x19F974, heap pointer (HEA) is 0x1A0000
[debug] AMX backtrace:
[debug] #0 0001f7c8 in public OnDialogResponse (0, 45, 1, -1, 1703928) from survival_mysql.amx
What I am guessing is that I've used too much arrays and it caused the script to have a massive difference between stack/heap size and estimated max usage. Any tips? Here is the code;

pawn Код:
ShowTargetInventory(playerid)
{
    new buffer[2028], test[MAX_PLAYERS], count[MAX_PLAYERS];
    for(new j = 0; j < inInfo[tradingPartner[playerid]][aSlots]; j++)
    {
        /*if(tradingItem1[playerid] == inInfo[tradingPartner[playerid]][iSlots][j] || tradingItem2[playerid] == inInfo[tradingPartner[playerid]][iSlots][j] || tradingItem3[playerid] == inInfo[tradingPartner[playerid]][iSlots][j])
        {
            test[playerid] = inInfo[tradingPartner[playerid]][iSlots][j];
            format(buffer, sizeof(buffer), "%s{FF0000}%d %s (%d)(YOU ALREADY SELECTED THIS ITEM)\n", buffer, j + 1, ItemNames[test[playerid]], inInfo[tradingPartner[playerid]][iAmount][j]);
            inInfo[tradingPartner[playerid]][dSlots][count[playerid]] = test[playerid];
            count[playerid]++;
        }*/

        //else
        //{
            test[playerid] = inInfo[tradingPartner[playerid]][iSlots][j];
            format(buffer, sizeof(buffer), "%s{0099cc}%d {FFFFFF}%s (%d)\n", buffer, j + 1, ItemNames[test[playerid]], inInfo[tradingPartner[playerid]][iAmount][j]);
            inInfo[tradingPartner[playerid]][dSlots][count[playerid]] = test[playerid];
            count[playerid]++;
        //}
    }
    new string[90];
    countsinventory[playerid]++;
    if(tradingcCount[playerid] != countsinventory[playerid])
        format(string, sizeof(string),"{0174DF}[R-SURVIVAL]: {FFFFFF}Trading System [ {FF0000}%d {FFFFFF}/ {00FF00}%d {FFFFFF}]", countsinventory[playerid], tradingcCount[playerid]);
    else
        format(string, sizeof(string),"{0174DF}[R-SURVIVAL]: {FFFFFF}Trading System [ {00FF00}%d {FFFFFF}/ {00FF00}%d {FFFFFF}]", countsinventory[playerid], tradingcCount[playerid]);
    ShowPlayerDialog(playerid, DIALOG_TRADINGREQITEMS, DIALOG_STYLE_LIST, string, buffer, "Select","Cancel");
}
Reply
#2

Solved. For anyone interested in solution, don't use too big arrays in your local variables. 2028 was unnecessarily big and I knew that but was kinda in a rush to publish this system and had plans to optimize it later on. Just don't.
Reply
#3

Quote:
Originally Posted by Rufio
Посмотреть сообщение
Solved. For anyone interested in solution, don't use too big arrays in your local variables. 2028 was unnecessarily big and I knew that but was kinda in a rush to publish this system and had plans to optimize it later on. Just don't.
I am interested but don't get what you mean..
What did you do with: new buffer[2028]?
Did you define it as a global variable or just made it new buffer[1024] or something?
Reply
#4

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
I am interested but don't get what you mean..
What did you do with: new buffer[2028]?
Did you define it as a global variable or just made it new buffer[1024] or something?


It was a local variable in the function. The buffer size was too big that it actually used all the memory allocated for the SA-MP server.

The buffer size is the variable size, which you define in the square brackets when you declare a variable.

PS: It's an array though xD
Reply
#5

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
I am interested but don't get what you mean..
What did you do with: new buffer[2028]?
Did you define it as a global variable or just made it new buffer[1024] or something?
Buffer was an array I declared locally, as I've set the size too big it used all the memory that is allocated for samp server. I used buffer to format my text.
No, it's not a global variable, it's a locally declared array. I changed it into 910 as I exactly need 910. It might differ for you if you are facing the same issue though.

Pretty what much Logic_ said.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)