PDA

View Full Version : Run time error


TheLeech
17/06/2019, 01:43 PM
This code gives an error at run time, and isn't loading factions, Same code basically to load houses ETC and they load fine.


forward Faction_Load();
public Faction_Load()
{
static
rows,
fields;

cache_get_data(rows, fields, g_iHandle);

for (new id = 0; id < rows; id ++) if (id < MAX_FACTIONS)
{
new fetch[2048];

FactionInfo[id][fDBID] = cache_get_field_int(id, "ID");

cache_get_field_content(id, "Name", fetch);
format(FactionInfo[id][fName], 128, fetch);

cache_get_field_content(id, "MOTD", fetch);
format(FactionInfo[id][fMOTD], 128, fetch);

FactionInfo[id][fRights] = cache_get_field_int(id, "Rights");
FactionInfo[id][fTagRights] = cache_get_field_int(id, "TagRights");
FactionInfo[id][fFactionChat] = cache_get_field_int(id, "FactionChat");

new RankName[MAX_FACTION_RANKS][64];
new RankBonus[MAX_FACTION_RANKS][32];

cache_get_field_content(id, "RankNames", fetch);
split(fetch, RankName, ',');

cache_get_field_content(id, "RankBonuses", fetch);
split(fetch, RankBonus, ',');

for(new i2 = 1; i2 < MAX_FACTION_RANKS; i2++)
{
format(FactionRankInfo[id][i2][fRank], 64, RankName[i2 - 1]);
FactionRankInfo[id][i2][fRankBonus] = strval(RankBonus[i2 - 1]);
}

FactionInfo[id][fWarehouseX] = cache_get_field_float(id, "WarehouseX");
FactionInfo[id][fWarehouseY] = cache_get_field_float(id, "WarehouseY");
FactionInfo[id][fWarehouseZ] = cache_get_field_float(id, "WarehouseZ");
FactionInfo[id][fWarehouseInterior] = cache_get_field_int(id, "WarehouseInterior");
FactionInfo[id][fWarehouseVirtualWorld] = cache_get_field_int(id, "WarehouseVirtualWorld");

FactionInfo[id][fDailyPackages] = cache_get_field_int(id, "DailyPackages");
FactionInfo[id][fAvailablePackages] = cache_get_field_int(id, "AvailablePackages");

if(FactionInfo[id][fWarehouseX] != 0 || FactionInfo[id][fWarehouseY] != 0 || FactionInfo[id][fWarehouseZ] != 0)
{
FactionCP[id] = CreateDynamicCP(FactionInfo[id][fWarehouseX], FactionInfo[id][fWarehouseY], FactionInfo[id][fWarehouseZ],
1.0, FactionInfo[id][fWarehouseVirtualWorld], FactionInfo[id][fWarehouseInterior]);
}

printf("Faction %i loaded! (Name: %s)", id, FactionInfo[id][fName]);
}
}


The run time error

[14:38:53] [debug] Run time error 3: "Stack/heap collision (insufficient stack size)"
[14:38:53] [debug] Stack pointer (STK) is 0x4F30DF0, heap pointer (HEA) is 0x4F30E2C
[14:38:53] [debug] AMX backtrace:
[14:38:53] [debug] #0 ???????? in public Faction_Load () from Compile.amx

Calisthenics
17/06/2019, 03:31 PM
Creating an array of size 2048 inside a loop is a bad idea. Reduce its size and move it before the loop.

Do not use format to copy a string, the function can store text if you specify the length.

cache_get_field_content(id, "Name", FactionInfo[id][fName], g_iHandle, 128);


Do not store ranks in the same table.