Raised This Month: $32 Target: $400
 8% 

String not saving after GetTrieString? Empty out of nowhere?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 06-27-2016 , 10:07   String not saving after GetTrieString? Empty out of nowhere?
Reply With Quote #1

So I'm using GetTrieString to retrieve a string, but when I go to play the sound in another function, I find that the string is empty somehow, even though the LogMessage directly after getting the string correctly plays the string.

PHP Code:
static String:g_szSoundOnSpinUp[MAXPLAYERS+1][PLATFORM_MAX_PATH];

SomeFunction(iClient//
{
    
g_szSoundOnSpinUp[iClient][0] = '\0'// This is the ONLY time that this ever gets cleared like this in the entire plugin.

    
GetTrieString(hTrie"onspinup"g_szSoundOnSpinUp[iClient], sizeof(g_szSoundOnSpinUp[]));
    
LogMessage("loaded %s"g_szSoundOnSpinUp[iClient]);
    
CPrintToChatAll("loaded %s on %N"g_szSoundOnSpinUp[iClient], iClient);
}

public 
OnGameFrame()
{
    static 
s;
    for (new 
1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && IsPlayerAlive(i) && !IsFakeClient(i))
        {
            
PrintToChatAll("%i %s %N"s++, g_szSoundOnSpinUp[i], i);
        }
    }

What gets logged/printed in chat is this:

LOG: loaded path/to/sound.wav
CHAT: loaded path/to/sound.wav on Chdata

Meanwhile chat gets rapidly spammed with an incrementing number with my name (1 Chdata, 2 Chdata, 3 Chdata), but that's it. Apparently g_szSoundOnSpinUp[i] is now suddenly empty.

What the heck?

I also tried changing

static String:g_szSoundOnSpinUp[MAXPLAYERS+1][PLATFORM_MAX_PATH];

to

new String:g_szSoundOnSpinUp[MAXPLAYERS+1][PLATFORM_MAX_PATH];

But nothing changed.
__________________

Last edited by Chdata; 06-27-2016 at 12:11.
Chdata is offline
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 06-27-2016 , 10:26   Re: String not saving after GetTrieString?
Reply With Quote #2

Where is SomeFunction called?
Could you provide the full code?

PS: you should perform your debug chat print on a command.
h3bus is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 06-27-2016 , 10:34   Re: String not saving after GetTrieString?
Reply With Quote #3

I was doing that debug on command at first, but the result is the same. I did it on gameframe to see if it was being set and then somehow getting cleared, but it acts as if it's never set in the first place.

SomeFunction is called in event_inventoryapplication.

Edit:

I made another global variable

static String:szWhat[PLATFORM_MAX_PATH]

And did strcopy(szWhat, sizeof(szWhat), g_szSoundOnSpinUp[iClient]);

Low and behold, szWhat kept the string properly and g_szSoundOnSpinUp was still empty

PHP Code:
public OnGameFrame() 

    static 
s
    for (new 
1<= MaxClientsi++) 
    { 
        if (
IsClientInGame(i) && IsPlayerAlive(i) && !IsFakeClient(i)) 
        { 
            
PrintToChatAll("%i %s %N %s"s++, g_szSoundOnSpinUp[i], iszWhat); 
        } 
    } 

0 Chdata path/to/sound.wav

I also did this in the same debug code

PHP Code:
                for (new 1<= MaxClientsi++)
                {
                    
PrintToChatAll("%i %s"ig_szSoundOnSpinUp[i]);
                } 
But got

Code:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24
edit: 1-33 are all empty.
__________________

Last edited by Chdata; 06-27-2016 at 10:57.
Chdata is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 06-27-2016 , 11:05   Re: String not saving after GetTrieString?
Reply With Quote #4

I'm finally getting error logs now.

Code:
L 06/27/2016 - 04:51:53: Error log file session closed.
L 06/27/2016 - 04:59:34: SourceMod error session started
L 06/27/2016 - 04:59:34: Info (map "pl_borneo") (file "errors_20160627.log")
L 06/27/2016 - 04:59:34: [SM] Exception reported: Plugin not runnable
L 06/27/2016 - 04:59:34: [SM] Exception reported: Plugin not runnable
L 06/27/2016 - 04:59:34: [SM] Exception reported: Plugin not runnable
L 06/27/2016 - 04:59:34: [SM] Exception reported: Plugin not runnable
L 06/27/2016 - 04:59:34: [SM] Exception reported: Plugin not runnable
L 06/27/2016 - 04:59:34: [SM] Exception reported: Plugin not runnable
L 06/27/2016 - 04:59:34: [SM] Exception reported: Plugin not runnable
L 06/27/2016 - 04:59:34: [SM] Exception reported: Plugin not runnable
L 06/27/2016 - 04:59:34: [SM] Exception reported: Plugin not runnable
L 06/27/2016 - 04:59:34: [SM] Exception reported: Plugin not runnable
L 06/27/2016 - 04:59:34: [SM] Exception reported: Plugin not runnable
57 lines of this

But it seems to be unrelated - earlier I attempted to load two plugins at the same time that register the same native/forward library (different filename, one is old, one is a new version). That might've been what that was.

The glitch I describe is happening through server restarts, my SM is updated to the latest snapshot.

Edit:

The minimal test case doesn't fail. Well, this is missing some of the stuff my full plugin does.

PHP Code:
#pragma semicolon 1
#include <sourcemod>

static String:g_szSoundOnSpinUp[MAXPLAYERS+1][PLATFORM_MAX_PATH]; // Does not matter if this is new String: - it still breaks.
static Handle:g_hTrie;

static 
Handle:fFrog;

public 
APLRes:AskPluginLoad2(Handle:myselfbool:lateString:error[], err_max)
{
    
fFrog CreateGlobalForward("CriticalFrog"ET_EventParam_CellParam_CellParam_StringParam_StringParam_String);
    
RegPluginLibrary("__0_frog");
    return 
APLRes_Success;
}

public 
OnPluginStart()
{
    
g_hTrie CreateTrie();
    
SetTrieString(g_hTrie"frog""random/string/of/stuff.avi");

    
LogMessage("saved \"random/string/of/stuff.avi\" to trie"); 
    
PrintToChatAll("saved \"random/string/of/stuff.avi\" to trie");

    
RegConsoleCmd("sm_frog"Command_Frog);
}

public 
Action:Command_Frog(iClientiArgs)

    
g_szSoundOnSpinUp[iClient][0] = '\0'// This is the ONLY time that this ever gets cleared like this in the entire plugin. 
    
GetTrieString(g_hTrie"frog"g_szSoundOnSpinUp[iClient], sizeof(g_szSoundOnSpinUp[])); 

    
LogMessage("loaded %s on %N"g_szSoundOnSpinUp[iClient], iClient); 
    
PrintToChatAll("loaded %s on %N"g_szSoundOnSpinUp[iClient], iClient);

    new 
Action:aAction Plugin_Continue;
    
Call_StartForward(fFrog);
    
Call_PushCell(0);
    
Call_PushCell(iClient);
    
Call_PushString("meet the frogger");
    
Call_PushString("frog-plugin");
    
Call_PushString("0.1 0.2 0.3");
    
Call_Finish(aAction);

    return 
Plugin_Handled;


public 
OnGameFrame() 

    static 
Float:flTime;
    if (
GetEngineTime() >= flTime)
    {
        for (new 
1<= MaxClientsi++) 
        { 
            if (
IsClientInGame(i) && IsPlayerAlive(i) && !IsFakeClient(i)) 
            {
                
LogMessage(" \nattempting to read");
                
PrintToChatAll(" \nattempting to read");
                if (
g_szSoundOnSpinUp[i][0] != '\0')
                {
                    
LogMessage("played %s on %N"g_szSoundOnSpinUp[i], i); 
                    
PrintToChatAll("played %s on %N"g_szSoundOnSpinUp[i], i);
                }
                
LogMessage("i hope i was able to read\n ");
                
PrintToChatAll("i hope i was able to read\n ");
            }
        }
        
flTime GetEngineTime() + 3.0;
    }

The code I practically copy pasted this from works just fine too - just it uses keyvalues instead of tries when it writes to the global string.

My plugin uses a lot of tries and arrays though, and sometimes its forwards fail... but always on the same scenarios.

And there's never error logs.

I might try testing again with some of my crappy nested adt trie array tries or w/e. But it's also loading a bunch of configs. Somewhere down the line maybe some memory somewhere is overflowing or something? idk. The kind of things that work fine make this very weird.
__________________

Last edited by Chdata; 06-27-2016 at 15:44.
Chdata is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 06-28-2016 , 09:43   Re: String not saving after GetTrieString? Empty out of nowhere?
Reply With Quote #5

Solved.

Because it's fired in Event_InventoryApplication, if I have two custom weapons equipped... it fires twice. Added check for if it's a primary weapon.

This is quite a Shroedinbug though...

"A design or implementation bug in a program that doesn't manifest until someone reading source or using the program in an unusual way notices that it never should have worked, at which point the program promptly stops working for everybody until fixed"

Cause it shouldn't be working in the original plugin because of the same problem <.<

----

Now to figure out why forwards aren't firing placed directly after logmessages/printtochats that work fine...

edit: it was firing, I just wasn't detecting stuff right and a config was screwed up somewhere

ohoho!!!
__________________

Last edited by Chdata; 06-28-2016 at 11:52.
Chdata 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 17:11.


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