Raised This Month: $51 Target: $400
 12% 

KeyValues problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jоnny
Senior Member
Join Date: Jun 2007
Old 08-14-2013 , 06:20   KeyValues problem
Reply With Quote #1



sometimes (with all same parameters, 500 items in stats) it works fine. But offten it says:

Quote:
L 08/14/2013 - 16:12:07: SourceMod error session started
L 08/14/2013 - 16:12:07: Info (map "c1m1_hotel") (file "errors_20130814.log")
L 08/14/2013 - 16:12:07: [SM] Plugin encountered error 20: Tracker stack is out of bounds
L 08/14/2013 - 16:12:07: [SM] Displaying call stack trace for plugin "testing.smx":
L 08/14/2013 - 16:12:07: [SM] [0] Line 112, testing.sp::SortStats()
L 08/14/2013 - 16:12:07: [SM] [1] Line 67, testing.sp::Command_Test3()
what i do wrong?
Jоnny is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 08-14-2013 , 12:03   Re: KeyValues problem
Reply With Quote #2

Does it only show that error when there are no KeyValues in the file? If so, you could try exiting if KvGotoFirstSubKey returns false.

PHP Code:
if (!KvGotoFirstSubKey(Stats))
{
    
CloseHandle(Stats);
    return;

__________________

Last edited by 11530; 08-14-2013 at 12:04.
11530 is offline
Jоnny
Senior Member
Join Date: Jun 2007
Old 08-14-2013 , 13:31   Re: KeyValues problem
Reply With Quote #3

Server says:
Quote:
Connection to Steam servers successful.
VAC secure mode is activated.
sm_t1 500
Generate stats...
Generate stats done -> addons\sourcemod\hardmod\players_stats.txt
sm_t3
Sorting...
SortStats(StatsCount) -> StatsCount = 500
Sorting done
sm_t3
Sorting...
SortStats(StatsCount) -> StatsCount = 500
and here we got error:
Quote:
L 08/14/2013 - 23:25:20: SourceMod error session started
L 08/14/2013 - 23:25:20: Info (map "c1m1_hotel") (file "errors_20130814.log")
L 08/14/2013 - 23:25:20: [SM] Plugin encountered error 20: Tracker stack is out of bounds
L 08/14/2013 - 23:25:20: [SM] Displaying call stack trace for plugin "testing.smx":
L 08/14/2013 - 23:25:20: [SM] [0] Line 112, testing.sp::SortStats()
L 08/14/2013 - 23:25:20: [SM] [1] Line 67, testing.sp::Command_Test3()
Code:
SortStats(StatsCount)
{
    PrintToServer("SortStats(StatsCount) -> StatsCount = %d", StatsCount);
    new Handle:Stats = CreateKeyValues("stats");
    FileToKeyValues(Stats, datafilepath);
//    new String:DataID[StatsCount][STEAM_AUTH_LENGTH + STEAM_NAME_LENGTH];
    new String:PlayerName[StatsCount][STEAM_NAME_LENGTH];
    // new points[StatsCount][2];
    // new bool:IsFuncFailed = true;
    if (!KvGotoFirstSubKey(Stats, true))
    {
        CloseHandle(Stats);
        return;
    }
    // new i = 0;
    // do
    // {
        // KvGetSectionName(Stats, DataID[i], STEAM_AUTH_LENGTH + STEAM_NAME_LENGTH);
        // KvGetString(Stats, "name", PlayerName[i], STEAM_NAME_LENGTH, "---");
        // points[i][0] = i;
        // points[i][1] = KvGetNum(Stats, "points", 0);
        // i++;
    // }
    // while KvGotoNextKey(Stats);
    CloseHandle(Stats);
  }
line 112 is bold
Jоnny is offline
Jоnny
Senior Member
Join Date: Jun 2007
Old 08-14-2013 , 13:35   Re: KeyValues problem
Reply With Quote #4

for if (!KvGotoFirstSubKey(Stats)) same error

Code:
#include <sourcemod>
#pragma semicolon 1
#pragma dynamic 65535

#define DATA_FILENAME "players_stats.txt"
#define STEAM_AUTH_LENGTH 32
#define STEAM_NAME_LENGTH 32

#define STATS_VERSION 63

#include <sourcemod>
#include <sdkhooks>
#include <sdktools>

#define PLUGIN_VERSION "0.1"
#define L4D_MAXPLAYERS 32
#define TEAM_SURVIVORS 2


public Plugin:myinfo = 
{
    name = "Tester",
    author = "Jonny",
    description = "",
    version = PLUGIN_VERSION,
    url = "http://www.sourcemod.net/"
};

new String:datafilepath[PLATFORM_MAX_PATH];

public OnPluginStart()
{
    RegAdminCmd("sm_t1", Command_Test1, ADMFLAG_ROOT, "");
    RegAdminCmd("sm_t2", Command_Test2, ADMFLAG_ROOT, "");
    RegAdminCmd("sm_t3", Command_Test3, ADMFLAG_ROOT, "");
    BuildPath(Path_SM, datafilepath, sizeof(datafilepath), "hardmod/%s", DATA_FILENAME);
}

public Action:Command_Test1(client, args)
{
    new count;
    if (args < 1) count = 1000;
    else
    {
        new String:string_count[8];
        GetCmdArg(1, string_count, sizeof(string_count));
        count = StringToInt(string_count);
    }

    PrintToServer("Generate stats...");
    GenerateStats(client, count);
    PrintToServer("Generate stats done -> %s", datafilepath);
}

public Action:Command_Test2(client, args)
{
    PrintToServer("Getting stats items count...");
    PrintToServer("Getting stats items count done -> %d", GetStatsCount());
}

public Action:Command_Test3(client, args)
{
    PrintToServer("Sorting...");
    SortStats(GetStatsCount());
    PrintToServer("Sorting done");
}

GenerateStats(client, count)
{
    new Handle:TempStats;
    TempStats = CreateKeyValues("stats");
    new String:StatsID[STEAM_AUTH_LENGTH + STEAM_NAME_LENGTH];
    for (new i = 0; i < count; i++)
    {
        Format(StatsID, STEAM_AUTH_LENGTH + STEAM_NAME_LENGTH, "STEAM_%d:%d:%d:noname", GetRandomInt(0, 1), GetRandomInt(0, 1), GetRandomInt(10000000, 99999999));
        KvJumpToKey(TempStats, StatsID, true);
        KvSetNum(TempStats, "points", GetRandomInt(-10000, 10000));
        KvSetString(TempStats, "name", "bla bla bla");
        KvSetNum(TempStats, "rank", 0);
        KvRewind(TempStats);
    }
    KeyValuesToFile(TempStats, datafilepath);
    CloseHandle(TempStats);
    if (client) PrintToChat(client, "Generate stats: done");
}

stock GetStatsCount()
{
    new StatsCount = 0;
    new Handle:Stats;
    Stats = CreateKeyValues("stats");
    FileToKeyValues(Stats, datafilepath);
    if (!KvGotoFirstSubKey(Stats)) return false;
    do
    {
        StatsCount++;
    }
    while KvGotoNextKey(Stats);
    CloseHandle(Stats);
    return StatsCount;
}

SortStats(StatsCount)
{
    PrintToServer("SortStats(StatsCount) -> StatsCount = %d", StatsCount);
    new Handle:Stats = CreateKeyValues("stats");
    FileToKeyValues(Stats, datafilepath);
    new String:PlayerName[StatsCount][STEAM_NAME_LENGTH];
    if (!KvGotoFirstSubKey(Stats))
    {
        CloseHandle(Stats);
        return;
    }
    CloseHandle(Stats);
}

public Sort_Function(array1[], array2[], const completearray[][], Handle:hndl)
{
    if (array1[1] > array2[1]) return -1;
    if (array1[1] == array2[1]) return 0;
    return 1;
}

Last edited by Jоnny; 08-14-2013 at 13:37.
Jоnny is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 08-14-2013 , 15:37   Re: KeyValues problem
Reply With Quote #5

Assuming STEAM_NAME_LENGTH somewhere near 32, you're creating an array of 500 strings of 32 bytes. That fills up the entire default stack limit at 16 KB.

Try one of the following:
  • Use an ADT array instead.
  • Use a global variable for temporary storage (not really a good design choice in this case).
  • Increase stack size with compiler parameters (look it up when you run spcomp).
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
Jоnny
Senior Member
Join Date: Jun 2007
Old 08-14-2013 , 15:43   Re: KeyValues problem
Reply With Quote #6

#pragma dynamic 65535 don't work?
Jоnny is offline
Jоnny
Senior Member
Join Date: Jun 2007
Old 08-14-2013 , 15:45   Re: KeyValues problem
Reply With Quote #7

Quote:
sm_t1 10
Generate stats...
Generate stats done -> addons\sourcemod\hardmod\players_stats.txt
sm_t3
Sorting...
SortStats(StatsCount) -> StatsCount = 10
Sorting done
sm_t3
Sorting...
SortStats(StatsCount) -> StatsCount = 10
Quote:
L 08/15/2013 - 01:45:10: SourceMod error session started
L 08/15/2013 - 01:45:10: Info (map "c1m1_hotel") (file "errors_20130815.log")
L 08/15/2013 - 01:45:10: [SM] Plugin encountered error 20: Tracker stack is out of bounds
L 08/15/2013 - 01:45:10: [SM] Displaying call stack trace for plugin "testing.smx":
L 08/15/2013 - 01:45:10: [SM] [0] Line 112, testing.sp::SortStats()
L 08/15/2013 - 01:45:10: [SM] [1] Line 67, testing.sp::Command_Test3()
Jоnny is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 08-14-2013 , 15:56   Re: KeyValues problem
Reply With Quote #8

Have a look at the S or s parameter in the compiler output when you run it without any parameters.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
psychonic

BAFFLED
Join Date: May 2008
Old 08-14-2013 , 16:46   Re: KeyValues problem
Reply With Quote #9

Are you running SM 1.6? You might be running into a bug with the new JIT.

Try 1.5 if that is the case.
psychonic is offline
Jоnny
Senior Member
Join Date: Jun 2007
Old 08-15-2013 , 00:43   Re: KeyValues problem
Reply With Quote #10

No errors on 1.5, thx
Jоnny is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:44.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode