HTML Code:
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
508550920
L 04/17/2014 - 16:38:42: [SM] Native "GetArraySize" reported: Invalid Handle 1e4
fdf08 (error: 4)
Here is the output from printing out the value of "GetArrayCell(g_hMapsDone[Type][Style], PlayerID)" every loop. The last output was 508550920, meaning the plugin didn't think it was an INVALID_HANDLE, and therefore skipped the if statement. Except it is still very much an INVALID_HANDLE, so GetArraySize didn't work on the hCell variable.
Here is the whole function:
PHP Code:
public LoadStats_Callback(Handle:owner, Handle:hndl, String:error[], any:data)
{
if(hndl != INVALID_HANDLE)
{
for(new Type; Type < MAX_TYPES; Type++)
{
for(new Style; Style < MAX_STYLES; Style++)
{
g_hMapsDone[Type][Style] = CreateArray();
g_hInitialized[Type][Style] = CreateArray();
}
}
new Position;
new lMapID, lType, lStyle;
new MapID, Type, Style, PlayerID, Float:Time;
while(SQL_FetchRow(hndl))
{
MapID = SQL_FetchInt(hndl, 0);
Type = SQL_FetchInt(hndl, 1);
Style = SQL_FetchInt(hndl, 2);
PlayerID = SQL_FetchInt(hndl, 3);
Time = SQL_FetchFloat(hndl, 4);
if(lMapID != MapID || lType != Type || lStyle != Style)
Position = 0;
Position++;
if(PlayerID >= GetArraySize(g_hMapsDone[Type][Style]))
{
ResizeArray(g_hMapsDone[Type][Style], PlayerID + 1);
ResizeArray(g_hInitialized[Type][Style], PlayerID + 1);
}
if(GetArrayCell(g_hMapsDone[Type][Style], PlayerID) == INVALID_HANDLE)
{
new Handle:hCell = CreateArray(3);
SetArrayCell(g_hMapsDone[Type][Style], PlayerID, hCell);
}
/*
if(GetArrayCell(g_hInitialized[Type][Style], PlayerID) != -1)
{
new Handle:hCell = CreateArray(3);
SetArrayCell(g_hMapsDone[Type][Style], PlayerID, hCell);
SetArrayCell(g_hInitialized[Type][Style], PlayerID, -1);
}
*/
new Handle:hCell = GetArrayCell(g_hMapsDone[Type][Style], PlayerID);
new iSize = GetArraySize(hCell);
ResizeArray(hCell, iSize + 1);
SetArrayCell(hCell, iSize, MapID, 0);
SetArrayCell(hCell, iSize, Position, 1);
SetArrayCell(hCell, iSize, Time, 2);
lMapID = MapID;
lType = Type;
lStyle = Style;
}
}
else
{
LogError(error);
}
}
The problem is in the ResizeArray function. A lot of unused indexes are junk numbers. Here is an example test.
PHP Code:
new Handle:hArray = CreateArray();
ResizeArray(hArray, 10000);
for(new i; i < 10000; i++)
if(GetArrayCell(hArray, i) != 0)
PrintToServer("%d", GetArrayCell(hArray, i));
There is a lot of crap in the array